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);
|
||||
});
|
||||
|
||||
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", () => {
|
||||
const result = template.expression(
|
||||
`
|
||||
|
||||
@ -1464,6 +1464,12 @@ defineType("ExportNamedDeclaration", {
|
||||
},
|
||||
),
|
||||
},
|
||||
assertions: {
|
||||
validate: chain(
|
||||
assertValueType("array"),
|
||||
assertNodeType("ImportAttribute"),
|
||||
),
|
||||
},
|
||||
specifiers: {
|
||||
default: [],
|
||||
validate: chain(
|
||||
@ -1559,6 +1565,12 @@ defineType("ImportDeclaration", {
|
||||
visitor: ["specifiers", "source"],
|
||||
aliases: ["Statement", "Declaration", "ModuleDeclaration"],
|
||||
fields: {
|
||||
assertions: {
|
||||
validate: chain(
|
||||
assertValueType("array"),
|
||||
assertNodeType("ImportAttribute"),
|
||||
),
|
||||
},
|
||||
specifiers: {
|
||||
validate: chain(
|
||||
assertValueType("array"),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user