fix: babel-types: ImportDeclaration: add assertions (#12263)
This commit is contained in:
parent
df908fc63b
commit
9eb661b285
@ -215,6 +215,39 @@ describe("@babel/template", function () {
|
|||||||
expect(result.test.left).toBe(value);
|
expect(result.test.left).toBe(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return assertions in ImportDeclaration when using .ast", () => {
|
||||||
|
const result = template.ast(
|
||||||
|
`import json from "./foo.json" assert { type: "json" };`,
|
||||||
|
{
|
||||||
|
plugins: ["importAssertions"],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.assertions[0].type).toBe("ImportAttribute");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return assertions in ExportNamedDeclaration when using .ast", () => {
|
||||||
|
const result = template.ast(
|
||||||
|
`export { foo2 } from "foo.json" assert { type: "json" };`,
|
||||||
|
{
|
||||||
|
plugins: ["importAssertions"],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.assertions[0].type).toBe("ImportAttribute");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return assertions in ExportDefaultDeclaration when using .ast", () => {
|
||||||
|
const result = template.ast(
|
||||||
|
`export foo2 from "foo.json" assert { type: "json" };`,
|
||||||
|
{
|
||||||
|
plugins: ["importAssertions", "exportDefaultFrom"],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.assertions[0].type).toBe("ImportAttribute");
|
||||||
|
});
|
||||||
|
|
||||||
it("should replace JSX placeholder", () => {
|
it("should replace JSX placeholder", () => {
|
||||||
const result = template.expression(
|
const result = template.expression(
|
||||||
`
|
`
|
||||||
|
|||||||
@ -1464,6 +1464,12 @@ defineType("ExportNamedDeclaration", {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
assertions: {
|
||||||
|
validate: chain(
|
||||||
|
assertValueType("array"),
|
||||||
|
assertNodeType("ImportAttribute"),
|
||||||
|
),
|
||||||
|
},
|
||||||
specifiers: {
|
specifiers: {
|
||||||
default: [],
|
default: [],
|
||||||
validate: chain(
|
validate: chain(
|
||||||
@ -1559,6 +1565,12 @@ defineType("ImportDeclaration", {
|
|||||||
visitor: ["specifiers", "source"],
|
visitor: ["specifiers", "source"],
|
||||||
aliases: ["Statement", "Declaration", "ModuleDeclaration"],
|
aliases: ["Statement", "Declaration", "ModuleDeclaration"],
|
||||||
fields: {
|
fields: {
|
||||||
|
assertions: {
|
||||||
|
validate: chain(
|
||||||
|
assertValueType("array"),
|
||||||
|
assertNodeType("ImportAttribute"),
|
||||||
|
),
|
||||||
|
},
|
||||||
specifiers: {
|
specifiers: {
|
||||||
validate: chain(
|
validate: chain(
|
||||||
assertValueType("array"),
|
assertValueType("array"),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user