Use printObject to print import attributes (#17329)
This commit is contained in:
1 parent
046ec13b0a
commit
66eaaaa69a
7 files changed
+303
-65
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### Allow break import attributes into multiple lines (#17329 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
// Input
|
||||
import syntaxImportAssertions from "@babel/plugin-syntax-import-assertions" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true", IS_STANDALONE: "false" };
|
||||
|
||||
// Prettier stable
|
||||
import syntaxImportAssertions from "@babel/plugin-syntax-import-assertions" with { BABEL_8_BREAKING: "false", USE_ESM: "true", IS_STANDALONE: "false" };
|
||||
|
||||
// Prettier main
|
||||
import syntaxImportAssertions from "@babel/plugin-syntax-import-assertions" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true",
|
||||
IS_STANDALONE: "false",
|
||||
};
|
||||
```
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
line,
|
||||
softline,
|
||||
} from "../../document/builders.js";
|
||||
import { removeLines } from "../../document/utils.js";
|
||||
import { printDanglingComments } from "../../main/comments/print.js";
|
||||
import isNonEmptyArray from "../../utils/is-non-empty-array.js";
|
||||
import UnexpectedNodeError from "../../utils/unexpected-node-error.js";
|
||||
@@ -23,11 +24,15 @@ import {
|
||||
} from "../utils/index.js";
|
||||
import { printDecoratorsBeforeExport } from "./decorators.js";
|
||||
import { printDeclareToken } from "./misc.js";
|
||||
import { printObject } from "./object.js";
|
||||
|
||||
/**
|
||||
* @import {Doc} from "../../document/builders.js"
|
||||
*/
|
||||
|
||||
/*
|
||||
- `ImportDeclaration`
|
||||
*/
|
||||
function printImportDeclaration(path, options, print) {
|
||||
const { node } = path;
|
||||
/** @type{Doc[]} */
|
||||
@@ -49,8 +54,8 @@ const isDefaultExport = (node) =>
|
||||
/*
|
||||
- `ExportDefaultDeclaration`
|
||||
- `ExportNamedDeclaration`
|
||||
- `DeclareExportDeclaration`(flow)
|
||||
- `ExportAllDeclaration`
|
||||
- `DeclareExportDeclaration`(flow)
|
||||
- `DeclareExportAllDeclaration`(flow)
|
||||
*/
|
||||
function printExportDeclaration(path, options, print) {
|
||||
@@ -271,6 +276,34 @@ function getImportAttributesKeyword(node, options) {
|
||||
return isNonEmptyArray(node.attributes) ? "with" : undefined;
|
||||
}
|
||||
|
||||
const isSingleTypeImportAttributes = (node) => {
|
||||
const { attributes } = node;
|
||||
|
||||
if (attributes.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const [attribute] = attributes;
|
||||
const { type, key, value } = attribute;
|
||||
return (
|
||||
type === "ImportAttribute" &&
|
||||
((key.type === "Identifier" && key.name === "type") ||
|
||||
(isStringLiteral(key) && key.value === "type")) &&
|
||||
isStringLiteral(value) &&
|
||||
!hasComment(attribute) &&
|
||||
!hasComment(key) &&
|
||||
!hasComment(value)
|
||||
);
|
||||
};
|
||||
|
||||
/*
|
||||
- `ImportDeclaration`
|
||||
- `ExportDefaultDeclaration`
|
||||
- `ExportNamedDeclaration`
|
||||
- `ExportAllDeclaration`
|
||||
- `DeclareExportDeclaration` (Flow)
|
||||
- `DeclareExportAllDeclaration` (Flow)
|
||||
*/
|
||||
function printImportAttributes(path, options, print) {
|
||||
const { node } = path;
|
||||
|
||||
@@ -283,23 +316,12 @@ function printImportAttributes(path, options, print) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/** @type{Doc[]} */
|
||||
const parts = [` ${keyword} {`];
|
||||
|
||||
if (isNonEmptyArray(node.attributes)) {
|
||||
if (options.bracketSpacing) {
|
||||
parts.push(" ");
|
||||
}
|
||||
|
||||
parts.push(join(", ", path.map(print, "attributes")));
|
||||
|
||||
if (options.bracketSpacing) {
|
||||
parts.push(" ");
|
||||
}
|
||||
let attributesDoc = printObject(path, options, print);
|
||||
if (isSingleTypeImportAttributes(node)) {
|
||||
attributesDoc = removeLines(attributesDoc);
|
||||
}
|
||||
parts.push("}");
|
||||
|
||||
return parts;
|
||||
return [` ${keyword} `, attributesDoc];
|
||||
}
|
||||
|
||||
function printModuleSpecifier(path, options, print) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as assert from "#universal/assert";
|
||||
import {
|
||||
group,
|
||||
hardline,
|
||||
@@ -11,8 +12,10 @@ import hasNewline from "../../utils/has-newline.js";
|
||||
import hasNewlineInRange from "../../utils/has-newline-in-range.js";
|
||||
import isNonEmptyArray from "../../utils/is-non-empty-array.js";
|
||||
import { locEnd, locStart } from "../loc.js";
|
||||
import getTextWithoutComments from "../utils/get-text-without-comments.js";
|
||||
import {
|
||||
CommentCheckFlags,
|
||||
createTypeCheckFunction,
|
||||
getComments,
|
||||
hasComment,
|
||||
isNextLineEmpty,
|
||||
@@ -26,10 +29,39 @@ import { printTypeAnnotationProperty } from "./type-annotation.js";
|
||||
|
||||
/** @import {Doc} from "../../document/builders.js" */
|
||||
|
||||
const isPrintingImportAttributes = createTypeCheckFunction([
|
||||
"ImportDeclaration",
|
||||
"ExportDefaultDeclaration",
|
||||
"ExportNamedDeclaration",
|
||||
"ExportAllDeclaration",
|
||||
"DeclareExportDeclaration",
|
||||
"DeclareExportAllDeclaration",
|
||||
]);
|
||||
|
||||
/*
|
||||
- `ObjectExpression`
|
||||
- `ObjectPattern`
|
||||
- `RecordExpression`
|
||||
- `ImportDeclaration`
|
||||
- `ExportDefaultDeclaration`
|
||||
- `ExportNamedDeclaration`
|
||||
- `ExportAllDeclaration`
|
||||
- `ObjectTypeAnnotation` (Flow)
|
||||
- `EnumBooleanBody` (Flow)
|
||||
- `EnumNumberBody` (Flow)
|
||||
- `EnumBigIntBody` (Flow)
|
||||
- `EnumStringBody` (Flow)
|
||||
- `EnumSymbolBody` (Flow)
|
||||
- `DeclareExportDeclaration` (Flow)
|
||||
- `DeclareExportAllDeclaration` (Flow)
|
||||
- `TSInterfaceBody` (TypeScript)
|
||||
- `TSTypeLiteral` (TypeScript)
|
||||
- `TSEnumDeclaration`(TypeScript)
|
||||
*/
|
||||
function printObject(path, options, print) {
|
||||
const { node } = path;
|
||||
|
||||
const isTypeAnnotation = node.type === "ObjectTypeAnnotation";
|
||||
const isFlowTypeAnnotation = node.type === "ObjectTypeAnnotation";
|
||||
const isEnumBody =
|
||||
node.type === "TSEnumBody" ||
|
||||
node.type === "EnumBooleanBody" ||
|
||||
@@ -37,15 +69,22 @@ function printObject(path, options, print) {
|
||||
node.type === "EnumBigIntBody" ||
|
||||
node.type === "EnumStringBody" ||
|
||||
node.type === "EnumSymbolBody";
|
||||
const fields = [
|
||||
node.type === "TSTypeLiteral" || isEnumBody
|
||||
? "members"
|
||||
: node.type === "TSInterfaceBody"
|
||||
? "body"
|
||||
: "properties",
|
||||
];
|
||||
if (isTypeAnnotation) {
|
||||
fields.push("indexers", "callProperties", "internalSlots");
|
||||
const isInterfaceBody = node.type === "TSInterfaceBody";
|
||||
const isImportAttributes = isPrintingImportAttributes(node);
|
||||
|
||||
const fields = [];
|
||||
if (node.type === "TSTypeLiteral" || isEnumBody) {
|
||||
fields.push("members");
|
||||
} else if (isInterfaceBody) {
|
||||
fields.push("body");
|
||||
} else if (isImportAttributes) {
|
||||
fields.push("attributes");
|
||||
} else {
|
||||
fields.push("properties");
|
||||
|
||||
if (isFlowTypeAnnotation) {
|
||||
fields.push("indexers", "callProperties", "internalSlots");
|
||||
}
|
||||
}
|
||||
|
||||
// Unfortunately, things grouped together in the ast can be
|
||||
@@ -68,13 +107,13 @@ function printObject(path, options, print) {
|
||||
|
||||
const { parent, key } = path;
|
||||
const isFlowInterfaceLikeBody =
|
||||
isTypeAnnotation &&
|
||||
isFlowTypeAnnotation &&
|
||||
key === "body" &&
|
||||
(parent.type === "InterfaceDeclaration" ||
|
||||
parent.type === "DeclareInterface" ||
|
||||
parent.type === "DeclareClass");
|
||||
const shouldBreak =
|
||||
node.type === "TSInterfaceBody" ||
|
||||
isInterfaceBody ||
|
||||
isEnumBody ||
|
||||
isFlowInterfaceLikeBody ||
|
||||
(node.type === "ObjectPattern" &&
|
||||
@@ -95,15 +134,11 @@ function printObject(path, options, print) {
|
||||
(node.type !== "ObjectPattern" &&
|
||||
options.objectWrap === "preserve" &&
|
||||
propsAndLoc.length > 0 &&
|
||||
hasNewlineInRange(
|
||||
options.originalText,
|
||||
locStart(node),
|
||||
propsAndLoc[0].loc,
|
||||
));
|
||||
hasNewLineAfterLeftBrace(node, propsAndLoc[0], options));
|
||||
|
||||
const separator = isFlowInterfaceLikeBody
|
||||
? ";"
|
||||
: node.type === "TSInterfaceBody" || node.type === "TSTypeLiteral"
|
||||
: isInterfaceBody || node.type === "TSTypeLiteral"
|
||||
? options.semi
|
||||
? ";"
|
||||
: ifBreak("", ";")
|
||||
@@ -180,19 +215,20 @@ function printObject(path, options, print) {
|
||||
printTypeAnnotationProperty(path, print),
|
||||
]);
|
||||
} else {
|
||||
const spacing = options.bracketSpacing ? line : softline;
|
||||
content = [
|
||||
isFlowInterfaceLikeBody && isNonEmptyArray(node.properties)
|
||||
? printHardlineAfterHeritage(parent)
|
||||
: "",
|
||||
leftBrace,
|
||||
indent([options.bracketSpacing ? line : softline, ...props]),
|
||||
indent([spacing, ...props]),
|
||||
ifBreak(
|
||||
canHaveTrailingSeparator &&
|
||||
(separator !== "," || shouldPrintComma(options))
|
||||
? separator
|
||||
: "",
|
||||
),
|
||||
options.bracketSpacing ? line : softline,
|
||||
spacing,
|
||||
rightBrace,
|
||||
printOptionalToken(path),
|
||||
printTypeAnnotationProperty(path, print),
|
||||
@@ -244,4 +280,27 @@ function shouldHugTheOnlyParameter(node, name) {
|
||||
);
|
||||
}
|
||||
|
||||
function hasNewLineAfterLeftBrace(node, firstPropertyAndLoc, options) {
|
||||
const text = options.originalText;
|
||||
let leftBraceIndex = locStart(node);
|
||||
const firstPropertyStart = firstPropertyAndLoc.loc;
|
||||
|
||||
if (isPrintingImportAttributes(node)) {
|
||||
const start = locStart(node);
|
||||
const textBeforeAttributes = getTextWithoutComments(
|
||||
options,
|
||||
start,
|
||||
firstPropertyStart,
|
||||
);
|
||||
leftBraceIndex = start + textBeforeAttributes.lastIndexOf("{");
|
||||
}
|
||||
|
||||
/* c8 ignore next 3 */
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
assert.equal(text.charAt(leftBraceIndex), "{");
|
||||
}
|
||||
|
||||
return hasNewlineInRange(text, leftBraceIndex, firstPropertyStart);
|
||||
}
|
||||
|
||||
export { printObject };
|
||||
@@ -16,15 +16,17 @@ function getTextWithoutComments(options, start, end) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const commentLength = commentEnd - commentStart;
|
||||
const startIndex = commentStart - start;
|
||||
const endIndex = commentEnd - start;
|
||||
|
||||
text =
|
||||
text.slice(0, commentStart - start) +
|
||||
" ".repeat(commentLength) +
|
||||
text.slice(commentEnd - start);
|
||||
text.slice(0, startIndex) +
|
||||
text.slice(startIndex, endIndex).replaceAll(/[^\n]/gu, " ") +
|
||||
text.slice(endIndex);
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
assert.ok(text.length === end - start);
|
||||
assert.equal(text.length, end - start);
|
||||
}
|
||||
|
||||
return text;
|
||||
|
||||
@@ -70,18 +70,45 @@ parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
import a10 from "./aaaaaaaaaa.json" with {
|
||||
import a11 from "./aaaaaaaaaa.json" with {
|
||||
type: "json" };
|
||||
import a20 from "./aaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a30 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a40 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a50 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a60 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a70 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
import a12 from "./aaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a13 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a14 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a15 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a16 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a17 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
type: "json" };
|
||||
import a80
|
||||
import a18
|
||||
from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
|
||||
import a21 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
// comment
|
||||
type: "json"
|
||||
};
|
||||
import a22 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
type:
|
||||
// comment
|
||||
"json"
|
||||
};
|
||||
import a23 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
type:"json" // comment
|
||||
};
|
||||
|
||||
|
||||
import a31 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
/* comment */
|
||||
type: "json"
|
||||
};
|
||||
import a32 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
type:
|
||||
/* comment */
|
||||
"json"
|
||||
};
|
||||
import a33 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
type:"json" /* comment */
|
||||
};
|
||||
|
||||
import("./aaaaaaaaaa.json", {with: { type: "json" }})
|
||||
import("./aaaaaaaaaaaaaaaaaaaa.json", {with: { type: "json" }})
|
||||
import("./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json", {with: { type: "json" }})
|
||||
@@ -92,14 +119,40 @@ import("./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
import("./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json", {with: { type: "json" }})
|
||||
|
||||
=====================================output=====================================
|
||||
import a10 from "./aaaaaaaaaa.json" with { type: "json" };
|
||||
import a20 from "./aaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a30 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a40 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a50 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a60 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a70 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a80 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a11 from "./aaaaaaaaaa.json" with { type: "json" };
|
||||
import a12 from "./aaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a13 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a14 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a15 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a16 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a17 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a18 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
|
||||
import a21 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
// comment
|
||||
type: "json",
|
||||
};
|
||||
import a22 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
type:
|
||||
// comment
|
||||
"json",
|
||||
};
|
||||
import a23 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
type: "json", // comment
|
||||
};
|
||||
|
||||
import a31 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
/* comment */
|
||||
type: "json",
|
||||
};
|
||||
import a32 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
type:
|
||||
/* comment */
|
||||
"json",
|
||||
};
|
||||
import a33 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
type: "json" /* comment */,
|
||||
};
|
||||
|
||||
import("./aaaaaaaaaa.json", { with: { type: "json" } });
|
||||
import("./aaaaaaaaaaaaaaaaaaaa.json", { with: { type: "json" } });
|
||||
@@ -163,6 +216,50 @@ import json from "./foo.json" with { type: "json", type: "bar" };
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`multiple.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
import syntaxImportAssertions from "@babel/plugin-syntax-import-assertions" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true", IS_STANDALONE: "false" };
|
||||
|
||||
import a1 from "foo" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true", IS_STANDALONE: "false" };
|
||||
import a2 from "foo" with {BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true", IS_STANDALONE: "false" };
|
||||
import a3 from "foo" with {
|
||||
BABEL_8_BREAKING: "false", };
|
||||
import a4 from "foo" with { BABEL_8_BREAKING: "false", };
|
||||
|
||||
=====================================output=====================================
|
||||
import syntaxImportAssertions from "@babel/plugin-syntax-import-assertions" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true",
|
||||
IS_STANDALONE: "false",
|
||||
};
|
||||
|
||||
import a1 from "foo" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true",
|
||||
IS_STANDALONE: "false",
|
||||
};
|
||||
import a2 from "foo" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true",
|
||||
IS_STANDALONE: "false",
|
||||
};
|
||||
import a3 from "foo" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
};
|
||||
import a4 from "foo" with { BABEL_8_BREAKING: "false" };
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`non-type.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "typescript"]
|
||||
|
||||
@@ -1,15 +1,42 @@
|
||||
import a10 from "./aaaaaaaaaa.json" with {
|
||||
import a11 from "./aaaaaaaaaa.json" with {
|
||||
type: "json" };
|
||||
import a20 from "./aaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a30 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a40 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a50 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a60 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a70 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
import a12 from "./aaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a13 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a14 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a15 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a16 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
import a17 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with {
|
||||
type: "json" };
|
||||
import a80
|
||||
import a18
|
||||
from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with { type: "json" };
|
||||
|
||||
import a21 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
// comment
|
||||
type: "json"
|
||||
};
|
||||
import a22 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
type:
|
||||
// comment
|
||||
"json"
|
||||
};
|
||||
import a23 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
type:"json" // comment
|
||||
};
|
||||
|
||||
|
||||
import a31 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
/* comment */
|
||||
type: "json"
|
||||
};
|
||||
import a32 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
type:
|
||||
/* comment */
|
||||
"json"
|
||||
};
|
||||
import a33 from "./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" with{
|
||||
type:"json" /* comment */
|
||||
};
|
||||
|
||||
import("./aaaaaaaaaa.json", {with: { type: "json" }})
|
||||
import("./aaaaaaaaaaaaaaaaaaaa.json", {with: { type: "json" }})
|
||||
import("./aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json", {with: { type: "json" }})
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import syntaxImportAssertions from "@babel/plugin-syntax-import-assertions" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true", IS_STANDALONE: "false" };
|
||||
|
||||
import a1 from "foo" with {
|
||||
BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true", IS_STANDALONE: "false" };
|
||||
import a2 from "foo" with {BABEL_8_BREAKING: "false",
|
||||
USE_ESM: "true", IS_STANDALONE: "false" };
|
||||
import a3 from "foo" with {
|
||||
BABEL_8_BREAKING: "false", };
|
||||
import a4 from "foo" with { BABEL_8_BREAKING: "false", };
|
||||
Reference in new issue
Block a user