Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inject): isReference check bug #804

Merged
merged 4 commits into from
Apr 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
isReference test
linsk1998 committed Feb 14, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 73a6461562b1624f7d75c3010b643bd5e10869ec
5 changes: 5 additions & 0 deletions packages/inject/test/fixtures/is-reference/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { bar as foo } from "path";
console.log({ bar: foo });
class Foo { bar () { console.log(this) } }
export { Foo }
export { foo as bar }
86 changes: 48 additions & 38 deletions packages/inject/test/snapshots/test.js.md
Original file line number Diff line number Diff line change
@@ -2,48 +2,49 @@

The actual snapshot is saved in `test.js.snap`.

Generated by [AVA](https://ava.li).
Generated by [AVA](https://avajs.dev).

## generates * imports
## inserts a default import statement

> Snapshot 1

`import * as foo from 'foo';␊
`import { default as $ } from 'jquery';␊
console.log(foo.bar);␊
console.log(foo.baz);␊
$(() => {␊
console.log('ready');␊
});␊
`

## handles redundant keys
## uses the modules property

> Snapshot 1

`import { default as $inject_Buffer_isBuffer } from 'is-buffer';␊
`import { default as $ } from 'jquery';␊
$inject_Buffer_isBuffer('foo');␊
$(() => {␊
console.log('ready');␊
});␊
`

## handles shadowed variables
## inserts a named import statement

> Snapshot 1

`function launch($) {␊
$(() => {␊
console.log('ready');␊
});␊
}␊
`import { Promise as Promise } from 'es6-promise';␊
launch((fn) => fn());␊
Promise.all([thisThing, thatThing]).then(() => someOtherThing);␊
`

## handles shorthand properties
## overwrites keypaths

> Snapshot 1

`import { Promise as Promise } from 'es6-promise';␊
`import { default as $inject_Object_assign } from 'fixtures/keypaths/polyfills/object-assign.js';␊
const polyfills = { Promise };␊
polyfills.Promise.resolve().then(() => 'it works');␊
const original = { foo: 'bar' };␊
const clone = $inject_Object_assign({}, original);␊
export default clone;␊
`

## ignores existing imports
@@ -57,36 +58,46 @@ Generated by [AVA](https://ava.li).
});␊
`

## inserts a default import statement
## handles shadowed variables

> Snapshot 1

`import { default as $ } from 'jquery';␊
`function launch($) {␊
$(() => {␊
console.log('ready');␊
});␊
}␊
$(() => {␊
console.log('ready');␊
});␊
launch((fn) => fn());␊
`

## inserts a named import statement
## handles shorthand properties

> Snapshot 1

`import { Promise as Promise } from 'es6-promise';␊
Promise.all([thisThing, thatThing]).then(() => someOtherThing);␊
const polyfills = { Promise };␊
polyfills.Promise.resolve().then(() => 'it works');␊
`

## overwrites keypaths
## handles redundant keys

> Snapshot 1

`import { default as $inject_Object_assign } from 'fixtures/keypaths/polyfills/object-assign.js';␊
`import { default as $inject_Buffer_isBuffer } from 'is-buffer';␊
const original = { foo: 'bar' };␊
const clone = $inject_Object_assign({}, original);␊
$inject_Buffer_isBuffer('foo');␊
`

## generates * imports

> Snapshot 1

`import * as foo from 'foo';␊
export default clone;␊
console.log(foo.bar);␊
console.log(foo.baz);␊
`

## transpiles non-JS files but handles failures to parse
@@ -99,13 +110,12 @@ Generated by [AVA](https://ava.li).
assert.equal(foo, path.join('..', 'baz'));␊
`

## uses the modules property
## ignores check isReference is false

> Snapshot 1

`import { default as $ } from 'jquery';␊
$(() => {␊
console.log('ready');␊
});␊
`
`import { bar as foo } from "path";␊
console.log({ bar: foo });␊
class Foo { bar () { console.log(this) } }␊
export { Foo }␊
export { foo as bar }`
Binary file modified packages/inject/test/snapshots/test.js.snap
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/inject/test/test.js
Original file line number Diff line number Diff line change
@@ -70,3 +70,7 @@ test('generates * imports', (t) => {
test('transpiles non-JS files but handles failures to parse', (t) => {
compare(t, 'non-js', { relative: ['path', 'relative'] });
});

test('ignores check isReference is false', (t) => {
compare(t, 'is-reference', { bar:'path' });
});