Skip to content

Commit e0b3e26

Browse files
committed
Add tests for import assertions
Closes #90. I thought new code was needed to support them, but it turns out no changes were needed.
1 parent 80a8e61 commit e0b3e26

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

babel.config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"plugins": ["@babel/plugin-transform-flow-strip-types"]
2+
"plugins": [
3+
"@babel/plugin-syntax-import-assertions",
4+
"@babel/plugin-transform-flow-strip-types"
5+
]
36
}

package-lock.json

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"devDependencies": {
1212
"@babel/eslint-parser": "7.17.0",
13+
"@babel/plugin-syntax-import-assertions": "7.16.7",
1314
"@babel/plugin-transform-flow-strip-types": "7.16.7",
1415
"@typescript-eslint/parser": "5.16.0",
1516
"eslint": "8.12.0",

test/imports.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ const flowTests = {
15761576
`import type a, {b} from "a"`,
15771577
`import type {} from "a"`,
15781578
`import type { } from "a"`,
1579+
`import json from "./foo.json" assert { type: "json" };`,
15791580

15801581
// typeof
15811582
`import typeof a from "a"`,
@@ -1672,6 +1673,33 @@ const flowTests = {
16721673
errors: 1,
16731674
},
16741675

1676+
// Import assertions.
1677+
{
1678+
code: input`
1679+
|import json from "./foo.json" assert { type: "json" };
1680+
|import {b, a} from "./bar.json" assert {
1681+
| // json
1682+
| type: "json",
1683+
| a: "b",
1684+
|} /* bar */ /* end
1685+
| comment */
1686+
|;[].forEach()
1687+
`,
1688+
output: (actual) => {
1689+
expect(actual).toMatchInlineSnapshot(`
1690+
|import {a,b} from "./bar.json" assert {
1691+
| // json
1692+
| type: "json",
1693+
| a: "b",
1694+
|} /* bar */
1695+
|import json from "./foo.json" assert { type: "json" };/* end
1696+
| comment */
1697+
|;[].forEach()
1698+
`);
1699+
},
1700+
errors: 1,
1701+
},
1702+
16751703
// https://github.com/graphql/graphql-js/blob/64b194c6c9b9aaa1c139f1b7c3692a6ef851928e/src/execution/execute.js#L10-L69
16761704
{
16771705
code: input`
@@ -1812,6 +1840,7 @@ const typescriptTests = {
18121840
`import type {a} from "a"`,
18131841
`import type {} from "a"`,
18141842
`import type { } from "a"`,
1843+
`import json from "./foo.json" assert { type: "json" };`,
18151844

18161845
// type specifiers.
18171846
`import { type b, type c, a } from "a"`,
@@ -1939,6 +1968,33 @@ const typescriptTests = {
19391968
},
19401969
errors: 1,
19411970
},
1971+
1972+
// Import assertions.
1973+
{
1974+
code: input`
1975+
|import json from "./foo.json" assert { type: "json" };
1976+
|import {b, a} from "./bar.json" assert {
1977+
| // json
1978+
| type: "json",
1979+
| a: "b",
1980+
|} /* bar */ /* end
1981+
| comment */
1982+
|;[].forEach()
1983+
`,
1984+
output: (actual) => {
1985+
expect(actual).toMatchInlineSnapshot(`
1986+
|import {a,b} from "./bar.json" assert {
1987+
| // json
1988+
| type: "json",
1989+
| a: "b",
1990+
|} /* bar */
1991+
|import json from "./foo.json" assert { type: "json" };/* end
1992+
| comment */
1993+
|;[].forEach()
1994+
`);
1995+
},
1996+
errors: 1,
1997+
},
19421998
],
19431999
};
19442000

0 commit comments

Comments
 (0)