Handle .mts and .cts files in @babel/preset-typescript (#13838)
This commit is contained in:
parent
381277ae35
commit
718c6cb7de
@ -64,7 +64,7 @@ function shouldIgnore(name, ignore?: Array<string>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const EXTENSIONS = [".js", ".mjs", ".ts", ".tsx"];
|
const EXTENSIONS = [".js", ".mjs", ".ts", ".tsx", ".cts", ".mts"];
|
||||||
|
|
||||||
function findFile(filepath: string, allowJSON?: boolean) {
|
function findFile(filepath: string, allowJSON?: boolean) {
|
||||||
const matches = [];
|
const matches = [];
|
||||||
@ -134,6 +134,7 @@ function pushTask(taskName, taskDir, suite, suiteName) {
|
|||||||
? taskOpts.BABEL_8_BREAKING === false
|
? taskOpts.BABEL_8_BREAKING === false
|
||||||
: taskOpts.BABEL_8_BREAKING === true),
|
: taskOpts.BABEL_8_BREAKING === true),
|
||||||
options: taskOpts,
|
options: taskOpts,
|
||||||
|
doNotSetSourceType: taskOpts.DO_NOT_SET_SOURCE_TYPE,
|
||||||
externalHelpers:
|
externalHelpers:
|
||||||
taskOpts.externalHelpers ??
|
taskOpts.externalHelpers ??
|
||||||
!!tryResolve("@babel/plugin-external-helpers"),
|
!!tryResolve("@babel/plugin-external-helpers"),
|
||||||
@ -162,6 +163,7 @@ function pushTask(taskName, taskDir, suite, suiteName) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
delete taskOpts.BABEL_8_BREAKING;
|
delete taskOpts.BABEL_8_BREAKING;
|
||||||
|
delete taskOpts.DO_NOT_SET_SOURCE_TYPE;
|
||||||
|
|
||||||
// If there's node requirement, check it before pushing task
|
// If there's node requirement, check it before pushing task
|
||||||
if (taskOpts.minNodeVersion) {
|
if (taskOpts.minNodeVersion) {
|
||||||
|
|||||||
@ -230,6 +230,7 @@ function run(task) {
|
|||||||
expect: expected,
|
expect: expected,
|
||||||
exec,
|
exec,
|
||||||
options: opts,
|
options: opts,
|
||||||
|
doNotSetSourceType,
|
||||||
optionsDir,
|
optionsDir,
|
||||||
validateLogs,
|
validateLogs,
|
||||||
ignoreOutput,
|
ignoreOutput,
|
||||||
@ -245,7 +246,7 @@ function run(task) {
|
|||||||
filename: self.loc,
|
filename: self.loc,
|
||||||
filenameRelative: self.filename,
|
filenameRelative: self.filename,
|
||||||
sourceFileName: self.filename,
|
sourceFileName: self.filename,
|
||||||
sourceType: "script",
|
...(doNotSetSourceType ? {} : { sourceType: "script" }),
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
configFile: false,
|
configFile: false,
|
||||||
inputSourceMap: task.inputSourceMap || undefined,
|
inputSourceMap: task.inputSourceMap || undefined,
|
||||||
|
|||||||
@ -135,6 +135,10 @@ const TSErrors = makeErrorTemplates(
|
|||||||
"Private elements cannot have an accessibility modifier ('%0').",
|
"Private elements cannot have an accessibility modifier ('%0').",
|
||||||
ReadonlyForMethodSignature:
|
ReadonlyForMethodSignature:
|
||||||
"'readonly' modifier can only appear on a property declaration or index signature.",
|
"'readonly' modifier can only appear on a property declaration or index signature.",
|
||||||
|
ReservedArrowTypeParam:
|
||||||
|
"This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
|
||||||
|
ReservedTypeAssertion:
|
||||||
|
"This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
|
||||||
SetAccesorCannotHaveOptionalParameter:
|
SetAccesorCannotHaveOptionalParameter:
|
||||||
"A 'set' accessor cannot have an optional parameter.",
|
"A 'set' accessor cannot have an optional parameter.",
|
||||||
SetAccesorCannotHaveRestParameter:
|
SetAccesorCannotHaveRestParameter:
|
||||||
@ -359,12 +363,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
tsParseDelimitedList<T: N.Node>(
|
tsParseDelimitedList<T: N.Node>(
|
||||||
kind: ParsingContext,
|
kind: ParsingContext,
|
||||||
parseElement: () => T,
|
parseElement: () => T,
|
||||||
|
refTrailingCommaPos?: { value: number },
|
||||||
): T[] {
|
): T[] {
|
||||||
return nonNull(
|
return nonNull(
|
||||||
this.tsParseDelimitedListWorker(
|
this.tsParseDelimitedListWorker(
|
||||||
kind,
|
kind,
|
||||||
parseElement,
|
parseElement,
|
||||||
/* expectSuccess */ true,
|
/* expectSuccess */ true,
|
||||||
|
refTrailingCommaPos,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -377,13 +383,16 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
kind: ParsingContext,
|
kind: ParsingContext,
|
||||||
parseElement: () => ?T,
|
parseElement: () => ?T,
|
||||||
expectSuccess: boolean,
|
expectSuccess: boolean,
|
||||||
|
refTrailingCommaPos?: { value: number },
|
||||||
): ?(T[]) {
|
): ?(T[]) {
|
||||||
const result = [];
|
const result = [];
|
||||||
|
let trailingCommaPos = -1;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (this.tsIsListTerminator(kind)) {
|
if (this.tsIsListTerminator(kind)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
trailingCommaPos = -1;
|
||||||
|
|
||||||
const element = parseElement();
|
const element = parseElement();
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
@ -392,6 +401,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
result.push(element);
|
result.push(element);
|
||||||
|
|
||||||
if (this.eat(tt.comma)) {
|
if (this.eat(tt.comma)) {
|
||||||
|
trailingCommaPos = this.state.lastTokStart;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,6 +416,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (refTrailingCommaPos) {
|
||||||
|
refTrailingCommaPos.value = trailingCommaPos;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,6 +428,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
parseElement: () => T,
|
parseElement: () => T,
|
||||||
bracket: boolean,
|
bracket: boolean,
|
||||||
skipFirstToken: boolean,
|
skipFirstToken: boolean,
|
||||||
|
refTrailingCommaPos?: { value: number },
|
||||||
): T[] {
|
): T[] {
|
||||||
if (!skipFirstToken) {
|
if (!skipFirstToken) {
|
||||||
if (bracket) {
|
if (bracket) {
|
||||||
@ -423,7 +438,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = this.tsParseDelimitedList(kind, parseElement);
|
const result = this.tsParseDelimitedList(
|
||||||
|
kind,
|
||||||
|
parseElement,
|
||||||
|
refTrailingCommaPos,
|
||||||
|
);
|
||||||
|
|
||||||
if (bracket) {
|
if (bracket) {
|
||||||
this.expect(tt.bracketR);
|
this.expect(tt.bracketR);
|
||||||
@ -524,15 +543,21 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
this.unexpected();
|
this.unexpected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const refTrailingCommaPos = { value: -1 };
|
||||||
|
|
||||||
node.params = this.tsParseBracketedList(
|
node.params = this.tsParseBracketedList(
|
||||||
"TypeParametersOrArguments",
|
"TypeParametersOrArguments",
|
||||||
this.tsParseTypeParameter.bind(this),
|
this.tsParseTypeParameter.bind(this),
|
||||||
/* bracket */ false,
|
/* bracket */ false,
|
||||||
/* skipFirstToken */ true,
|
/* skipFirstToken */ true,
|
||||||
|
refTrailingCommaPos,
|
||||||
);
|
);
|
||||||
if (node.params.length === 0) {
|
if (node.params.length === 0) {
|
||||||
this.raise(node.start, TSErrors.EmptyTypeParameters);
|
this.raise(node.start, TSErrors.EmptyTypeParameters);
|
||||||
}
|
}
|
||||||
|
if (refTrailingCommaPos.value !== -1) {
|
||||||
|
this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
|
||||||
|
}
|
||||||
return this.finishNode(node, "TSTypeParameterDeclaration");
|
return this.finishNode(node, "TSTypeParameterDeclaration");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1403,6 +1428,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
tsParseTypeAssertion(): N.TsTypeAssertion {
|
tsParseTypeAssertion(): N.TsTypeAssertion {
|
||||||
|
if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
|
||||||
|
this.raise(this.state.start, TSErrors.ReservedTypeAssertion);
|
||||||
|
}
|
||||||
|
|
||||||
const node: N.TsTypeAssertion = this.startNode();
|
const node: N.TsTypeAssertion = this.startNode();
|
||||||
const _const = this.tsTryNextParseConstantContext();
|
const _const = this.tsTryNextParseConstantContext();
|
||||||
node.typeAnnotation = _const || this.tsNextThenParseType();
|
node.typeAnnotation = _const || this.tsNextThenParseType();
|
||||||
@ -2854,7 +2883,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
|
|
||||||
// Either way, we're looking at a '<': tt.jsxTagStart or relational.
|
// Either way, we're looking at a '<': tt.jsxTagStart or relational.
|
||||||
|
|
||||||
let typeParameters: N.TsTypeParameterDeclaration;
|
let typeParameters: ?N.TsTypeParameterDeclaration;
|
||||||
state = state || this.state.clone();
|
state = state || this.state.clone();
|
||||||
|
|
||||||
const arrow = this.tryParse(abort => {
|
const arrow = this.tryParse(abort => {
|
||||||
@ -2878,7 +2907,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
}, state);
|
}, state);
|
||||||
|
|
||||||
/*:: invariant(arrow.node != null) */
|
/*:: invariant(arrow.node != null) */
|
||||||
if (!arrow.error && !arrow.aborted) return arrow.node;
|
if (!arrow.error && !arrow.aborted) {
|
||||||
|
// This error is reported outside of the this.tryParse call so that
|
||||||
|
// in case of <T>(x) => 2, we don't consider <T>(x) as a type assertion
|
||||||
|
// because of this error.
|
||||||
|
if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
|
||||||
|
return arrow.node;
|
||||||
|
}
|
||||||
|
|
||||||
if (!jsx) {
|
if (!jsx) {
|
||||||
// Try parsing a type cast instead of an arrow function.
|
// Try parsing a type cast instead of an arrow function.
|
||||||
@ -2903,6 +2938,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
if (arrow.node) {
|
if (arrow.node) {
|
||||||
/*:: invariant(arrow.failState) */
|
/*:: invariant(arrow.failState) */
|
||||||
this.state = arrow.failState;
|
this.state = arrow.failState;
|
||||||
|
if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
|
||||||
return arrow.node;
|
return arrow.node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2919,6 +2955,16 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
throw jsx?.error || arrow.error || typeCast?.error;
|
throw jsx?.error || arrow.error || typeCast?.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportReservedArrowTypeParam(node: any) {
|
||||||
|
if (
|
||||||
|
node.params.length === 1 &&
|
||||||
|
!node.extra?.trailingComma &&
|
||||||
|
this.getPluginOption("typescript", "disallowAmbiguousJSXLike")
|
||||||
|
) {
|
||||||
|
this.raise(node.start, TSErrors.ReservedArrowTypeParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle type assertions
|
// Handle type assertions
|
||||||
parseMaybeUnary(refExpressionErrors?: ?ExpressionErrors): N.Expression {
|
parseMaybeUnary(refExpressionErrors?: ?ExpressionErrors): N.Expression {
|
||||||
if (!this.hasPlugin("jsx") && this.isRelational("<")) {
|
if (!this.hasPlugin("jsx") && this.isRelational("<")) {
|
||||||
|
|||||||
3
packages/babel-parser/test/fixtures/typescript/disallow-jsx-ambiguity/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/disallow-jsx-ambiguity/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": [["typescript", { "disallowAmbiguousJSXLike": true }]]
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<T>x;
|
||||||
38
packages/babel-parser/test/fixtures/typescript/disallow-jsx-ambiguity/type-assertion/output.json
vendored
Normal file
38
packages/babel-parser/test/fixtures/typescript/disallow-jsx-ambiguity/type-assertion/output.json
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
|
||||||
|
"errors": [
|
||||||
|
"SyntaxError: This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead. (1:0)"
|
||||||
|
],
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
|
||||||
|
"sourceType": "script",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
|
||||||
|
"expression": {
|
||||||
|
"type": "TSTypeAssertion",
|
||||||
|
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeReference",
|
||||||
|
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}},
|
||||||
|
"typeName": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2},"identifierName":"T"},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expression": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4},"identifierName":"x"},
|
||||||
|
"name": "x"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
<T>() => 1;
|
||||||
|
<T>(x) => 1;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": false
|
||||||
|
}
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}},
|
||||||
|
"errors": [
|
||||||
|
"SyntaxError: This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (1:0)",
|
||||||
|
"SyntaxError: This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (2:0)"
|
||||||
|
],
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}},
|
||||||
|
"sourceType": "script",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ArrowFunctionExpression",
|
||||||
|
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
|
||||||
|
"id": null,
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [],
|
||||||
|
"body": {
|
||||||
|
"type": "NumericLiteral",
|
||||||
|
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": 1,
|
||||||
|
"raw": "1"
|
||||||
|
},
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterDeclaration",
|
||||||
|
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeParameter",
|
||||||
|
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":12,"end":24,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":12}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ArrowFunctionExpression",
|
||||||
|
"start":12,"end":23,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":11}},
|
||||||
|
"id": null,
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":16,"end":17,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"x"},
|
||||||
|
"name": "x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"type": "NumericLiteral",
|
||||||
|
"start":22,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": 1,
|
||||||
|
"raw": "1"
|
||||||
|
},
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterDeclaration",
|
||||||
|
"start":12,"end":15,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeParameter",
|
||||||
|
"start":13,"end":14,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2}},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
<T,>() => 1;
|
||||||
|
<T,>(x) => 1;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": false
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":13}},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":13}},
|
||||||
|
"sourceType": "script",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ArrowFunctionExpression",
|
||||||
|
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
|
||||||
|
"id": null,
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [],
|
||||||
|
"body": {
|
||||||
|
"type": "NumericLiteral",
|
||||||
|
"start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": 1,
|
||||||
|
"raw": "1"
|
||||||
|
},
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterDeclaration",
|
||||||
|
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeParameter",
|
||||||
|
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extra": {
|
||||||
|
"trailingComma": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":13,"end":26,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":13}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ArrowFunctionExpression",
|
||||||
|
"start":13,"end":25,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":12}},
|
||||||
|
"id": null,
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":18,"end":19,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6},"identifierName":"x"},
|
||||||
|
"name": "x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"type": "NumericLiteral",
|
||||||
|
"start":24,"end":25,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":12}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": 1,
|
||||||
|
"raw": "1"
|
||||||
|
},
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterDeclaration",
|
||||||
|
"start":13,"end":17,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":4}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeParameter",
|
||||||
|
"start":14,"end":15,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2}},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extra": {
|
||||||
|
"trailingComma": 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
<T,>() => 1;
|
||||||
|
<T,>(x) => 1;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": true
|
||||||
|
}
|
||||||
@ -0,0 +1,97 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":13}},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":13}},
|
||||||
|
"sourceType": "script",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ArrowFunctionExpression",
|
||||||
|
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
|
||||||
|
"id": null,
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [],
|
||||||
|
"body": {
|
||||||
|
"type": "NumericLiteral",
|
||||||
|
"start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": 1,
|
||||||
|
"raw": "1"
|
||||||
|
},
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterDeclaration",
|
||||||
|
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeParameter",
|
||||||
|
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}},
|
||||||
|
"name": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2},"identifierName":"T"},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extra": {
|
||||||
|
"trailingComma": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":13,"end":26,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":13}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ArrowFunctionExpression",
|
||||||
|
"start":13,"end":25,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":12}},
|
||||||
|
"id": null,
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":18,"end":19,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6},"identifierName":"x"},
|
||||||
|
"name": "x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"type": "NumericLiteral",
|
||||||
|
"start":24,"end":25,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":12}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": 1,
|
||||||
|
"raw": "1"
|
||||||
|
},
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterDeclaration",
|
||||||
|
"start":13,"end":17,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":4}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeParameter",
|
||||||
|
"start":14,"end":15,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2}},
|
||||||
|
"name": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":14,"end":15,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2},"identifierName":"T"},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extra": {
|
||||||
|
"trailingComma": 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
<T>() => 1;
|
||||||
|
<T>(x) => 1;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": true
|
||||||
|
}
|
||||||
95
packages/babel-parser/test/fixtures/typescript/disallow-jsx-ambiguity/type-parameter/output.json
vendored
Normal file
95
packages/babel-parser/test/fixtures/typescript/disallow-jsx-ambiguity/type-parameter/output.json
vendored
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}},
|
||||||
|
"errors": [
|
||||||
|
"SyntaxError: This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (1:0)",
|
||||||
|
"SyntaxError: This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (2:0)"
|
||||||
|
],
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}},
|
||||||
|
"sourceType": "script",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ArrowFunctionExpression",
|
||||||
|
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
|
||||||
|
"id": null,
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [],
|
||||||
|
"body": {
|
||||||
|
"type": "NumericLiteral",
|
||||||
|
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": 1,
|
||||||
|
"raw": "1"
|
||||||
|
},
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterDeclaration",
|
||||||
|
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeParameter",
|
||||||
|
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}},
|
||||||
|
"name": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2},"identifierName":"T"},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":12,"end":24,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":12}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ArrowFunctionExpression",
|
||||||
|
"start":12,"end":23,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":11}},
|
||||||
|
"id": null,
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":16,"end":17,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"x"},
|
||||||
|
"name": "x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"type": "NumericLiteral",
|
||||||
|
"start":22,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": 1,
|
||||||
|
"raw": "1"
|
||||||
|
},
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterDeclaration",
|
||||||
|
"start":12,"end":15,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeParameter",
|
||||||
|
"start":13,"end":14,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2}},
|
||||||
|
"name": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":13,"end":14,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2},"identifierName":"T"},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -185,6 +185,7 @@ export interface FlowPluginOptions {
|
|||||||
|
|
||||||
export interface TypeScriptPluginOptions {
|
export interface TypeScriptPluginOptions {
|
||||||
dts?: boolean;
|
dts?: boolean;
|
||||||
|
disallowAmbiguousJSXLike?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const tokTypes: {
|
export const tokTypes: {
|
||||||
|
|||||||
@ -24,7 +24,8 @@
|
|||||||
"@babel/core": "^7.0.0-0"
|
"@babel/core": "^7.0.0-0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "workspace:^"
|
"@babel/core": "workspace:^",
|
||||||
|
"@babel/helper-plugin-test-runner": "workspace:^"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.9.0"
|
"node": ">=6.9.0"
|
||||||
|
|||||||
@ -15,7 +15,7 @@ function removePlugin(plugins, name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default declare((api, { isTSX }) => {
|
export default declare((api, { isTSX, disallowAmbiguousJSXLike }) => {
|
||||||
api.assertVersion(7);
|
api.assertVersion(7);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -31,7 +31,10 @@ export default declare((api, { isTSX }) => {
|
|||||||
// in TS depends on the extensions, and is purely dependent on 'isTSX'.
|
// in TS depends on the extensions, and is purely dependent on 'isTSX'.
|
||||||
removePlugin(plugins, "jsx");
|
removePlugin(plugins, "jsx");
|
||||||
|
|
||||||
parserOpts.plugins.push("typescript", "classProperties");
|
parserOpts.plugins.push(
|
||||||
|
["typescript", { disallowAmbiguousJSXLike }],
|
||||||
|
"classProperties",
|
||||||
|
);
|
||||||
|
|
||||||
if (!process.env.BABEL_8_BREAKING) {
|
if (!process.env.BABEL_8_BREAKING) {
|
||||||
// This is enabled by default since @babel/parser 7.1.5
|
// This is enabled by default since @babel/parser 7.1.5
|
||||||
|
|||||||
3
packages/babel-plugin-syntax-typescript/test/fixtures/disallow-jsx-ambiguity/options.json
vendored
Normal file
3
packages/babel-plugin-syntax-typescript/test/fixtures/disallow-jsx-ambiguity/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": [["syntax-typescript", { "disallowAmbiguousJSXLike": true }]]
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<T>x;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead. (1:0)"
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
<T,>() => 1;
|
||||||
|
<T,>(x) => 1;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
<T>() => 1;
|
||||||
|
|
||||||
|
<T>(x) => 1;
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
<T>() => 1;
|
||||||
|
<T>(x) => 1;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (1:0)"
|
||||||
|
}
|
||||||
3
packages/babel-plugin-syntax-typescript/test/index.js
Normal file
3
packages/babel-plugin-syntax-typescript/test/index.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
|
runner(import.meta.url);
|
||||||
@ -8,6 +8,7 @@ export default declare((api, opts) => {
|
|||||||
const {
|
const {
|
||||||
allExtensions,
|
allExtensions,
|
||||||
allowNamespaces,
|
allowNamespaces,
|
||||||
|
disallowAmbiguousJSXLike,
|
||||||
isTSX,
|
isTSX,
|
||||||
jsxPragma,
|
jsxPragma,
|
||||||
jsxPragmaFrag,
|
jsxPragmaFrag,
|
||||||
@ -16,17 +17,19 @@ export default declare((api, opts) => {
|
|||||||
} = normalizeOptions(opts);
|
} = normalizeOptions(opts);
|
||||||
|
|
||||||
const pluginOptions = process.env.BABEL_8_BREAKING
|
const pluginOptions = process.env.BABEL_8_BREAKING
|
||||||
? isTSX => ({
|
? (isTSX, disallowAmbiguousJSXLike) => ({
|
||||||
allowNamespaces,
|
allowNamespaces,
|
||||||
|
disallowAmbiguousJSXLike,
|
||||||
isTSX,
|
isTSX,
|
||||||
jsxPragma,
|
jsxPragma,
|
||||||
jsxPragmaFrag,
|
jsxPragmaFrag,
|
||||||
onlyRemoveTypeImports,
|
onlyRemoveTypeImports,
|
||||||
optimizeConstEnums,
|
optimizeConstEnums,
|
||||||
})
|
})
|
||||||
: isTSX => ({
|
: (isTSX, disallowAmbiguousJSXLike) => ({
|
||||||
allowDeclareFields: opts.allowDeclareFields,
|
allowDeclareFields: opts.allowDeclareFields,
|
||||||
allowNamespaces,
|
allowNamespaces,
|
||||||
|
disallowAmbiguousJSXLike,
|
||||||
isTSX,
|
isTSX,
|
||||||
jsxPragma,
|
jsxPragma,
|
||||||
jsxPragmaFrag,
|
jsxPragmaFrag,
|
||||||
@ -38,21 +41,36 @@ export default declare((api, opts) => {
|
|||||||
overrides: allExtensions
|
overrides: allExtensions
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
plugins: [[transformTypeScript, pluginOptions(isTSX)]],
|
plugins: [
|
||||||
|
[
|
||||||
|
transformTypeScript,
|
||||||
|
pluginOptions(isTSX, disallowAmbiguousJSXLike),
|
||||||
|
],
|
||||||
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: [
|
: // Only set 'test' if explicitly requested, since it requires that
|
||||||
|
// Babel is being called`
|
||||||
|
[
|
||||||
{
|
{
|
||||||
// Only set 'test' if explicitly requested, since it requires that
|
|
||||||
// Babel is being called`
|
|
||||||
test: /\.ts$/,
|
test: /\.ts$/,
|
||||||
plugins: [[transformTypeScript, pluginOptions(false)]],
|
plugins: [[transformTypeScript, pluginOptions(false, false)]],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.mts$/,
|
||||||
|
sourceType: "module",
|
||||||
|
plugins: [[transformTypeScript, pluginOptions(false, true)]],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.cts$/,
|
||||||
|
sourceType: "script",
|
||||||
|
plugins: [[transformTypeScript, pluginOptions(false, true)]],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Only set 'test' if explicitly requested, since it requires that
|
|
||||||
// Babel is being called`
|
|
||||||
test: /\.tsx$/,
|
test: /\.tsx$/,
|
||||||
plugins: [[transformTypeScript, pluginOptions(true)]],
|
// disallowAmbiguousJSXLike is a no-op when parsing TSX, since it's
|
||||||
|
// always disallowed.
|
||||||
|
plugins: [[transformTypeScript, pluginOptions(true, false)]],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,6 +7,7 @@ export default function normalizeOptions(options = {}) {
|
|||||||
const TopLevelOptions = {
|
const TopLevelOptions = {
|
||||||
allExtensions: "allExtensions",
|
allExtensions: "allExtensions",
|
||||||
allowNamespaces: "allowNamespaces",
|
allowNamespaces: "allowNamespaces",
|
||||||
|
disallowAmbiguousJSXLike: "disallowAmbiguousJSXLike",
|
||||||
isTSX: "isTSX",
|
isTSX: "isTSX",
|
||||||
jsxPragma: "jsxPragma",
|
jsxPragma: "jsxPragma",
|
||||||
jsxPragmaFrag: "jsxPragmaFrag",
|
jsxPragmaFrag: "jsxPragmaFrag",
|
||||||
@ -54,6 +55,18 @@ export default function normalizeOptions(options = {}) {
|
|||||||
v.invariant(allExtensions, "isTSX:true requires allExtensions:true");
|
v.invariant(allExtensions, "isTSX:true requires allExtensions:true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const disallowAmbiguousJSXLike = v.validateBooleanOption(
|
||||||
|
TopLevelOptions.disallowAmbiguousJSXLike,
|
||||||
|
options.disallowAmbiguousJSXLike,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
if (disallowAmbiguousJSXLike) {
|
||||||
|
v.invariant(
|
||||||
|
allExtensions,
|
||||||
|
"disallowAmbiguousJSXLike:true requires allExtensions:true",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const optimizeConstEnums = v.validateBooleanOption(
|
const optimizeConstEnums = v.validateBooleanOption(
|
||||||
TopLevelOptions.optimizeConstEnums,
|
TopLevelOptions.optimizeConstEnums,
|
||||||
options.optimizeConstEnums,
|
options.optimizeConstEnums,
|
||||||
@ -63,6 +76,7 @@ export default function normalizeOptions(options = {}) {
|
|||||||
return {
|
return {
|
||||||
allExtensions,
|
allExtensions,
|
||||||
allowNamespaces,
|
allowNamespaces,
|
||||||
|
disallowAmbiguousJSXLike,
|
||||||
isTSX,
|
isTSX,
|
||||||
jsxPragma,
|
jsxPragma,
|
||||||
jsxPragmaFrag,
|
jsxPragmaFrag,
|
||||||
|
|||||||
1
packages/babel-preset-typescript/test/fixtures/node-extensions/import-in-cts/input.cts
vendored
Normal file
1
packages/babel-preset-typescript/test/fixtures/node-extensions/import-in-cts/input.cts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "x";
|
||||||
3
packages/babel-preset-typescript/test/fixtures/node-extensions/import-in-cts/options.json
vendored
Normal file
3
packages/babel-preset-typescript/test/fixtures/node-extensions/import-in-cts/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "'import' and 'export' may appear only with 'sourceType: \"module\"' (1:0)"
|
||||||
|
}
|
||||||
1
packages/babel-preset-typescript/test/fixtures/node-extensions/import-in-mts/input.mts
vendored
Normal file
1
packages/babel-preset-typescript/test/fixtures/node-extensions/import-in-mts/input.mts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "x";
|
||||||
1
packages/babel-preset-typescript/test/fixtures/node-extensions/import-in-mts/output.mjs
vendored
Normal file
1
packages/babel-preset-typescript/test/fixtures/node-extensions/import-in-mts/output.mjs
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "x";
|
||||||
4
packages/babel-preset-typescript/test/fixtures/node-extensions/options.json
vendored
Normal file
4
packages/babel-preset-typescript/test/fixtures/node-extensions/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"DO_NOT_SET_SOURCE_TYPE": true,
|
||||||
|
"presets": ["typescript"]
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<T> x;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead. (1:0)"
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<T> x;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead. (1:0)"
|
||||||
|
}
|
||||||
1
packages/babel-preset-typescript/test/fixtures/node-extensions/type-assertion-in-ts/input.ts
vendored
Normal file
1
packages/babel-preset-typescript/test/fixtures/node-extensions/type-assertion-in-ts/input.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<T> x;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"DO_NOT_SET_SOURCE_TYPE": false
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
x;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<T>() => 0;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (1:0)"
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<T>() => 0;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`. (1:0)"
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<T>() => 0;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"DO_NOT_SET_SOURCE_TYPE": false
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
() => 0;
|
||||||
1
packages/babel-preset-typescript/test/fixtures/node-extensions/with-in-cts/input.cts
vendored
Normal file
1
packages/babel-preset-typescript/test/fixtures/node-extensions/with-in-cts/input.cts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
with (x) {}
|
||||||
1
packages/babel-preset-typescript/test/fixtures/node-extensions/with-in-cts/output.js
vendored
Normal file
1
packages/babel-preset-typescript/test/fixtures/node-extensions/with-in-cts/output.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
with (x) {}
|
||||||
1
packages/babel-preset-typescript/test/fixtures/node-extensions/with-in-mts/input.mts
vendored
Normal file
1
packages/babel-preset-typescript/test/fixtures/node-extensions/with-in-mts/input.mts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
with (x) {}
|
||||||
3
packages/babel-preset-typescript/test/fixtures/node-extensions/with-in-mts/options.json
vendored
Normal file
3
packages/babel-preset-typescript/test/fixtures/node-extensions/with-in-mts/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "'with' in strict mode. (1:0)"
|
||||||
|
}
|
||||||
@ -30,16 +30,17 @@ describe("normalize options", () => {
|
|||||||
});
|
});
|
||||||
it("default values", () => {
|
it("default values", () => {
|
||||||
expect(normalizeOptions({})).toMatchInlineSnapshot(`
|
expect(normalizeOptions({})).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"allExtensions": false,
|
"allExtensions": false,
|
||||||
"allowNamespaces": true,
|
"allowNamespaces": true,
|
||||||
"isTSX": false,
|
"disallowAmbiguousJSXLike": false,
|
||||||
"jsxPragma": "React",
|
"isTSX": false,
|
||||||
"jsxPragmaFrag": "React.Fragment",
|
"jsxPragma": "React",
|
||||||
"onlyRemoveTypeImports": true,
|
"jsxPragmaFrag": "React.Fragment",
|
||||||
"optimizeConstEnums": false,
|
"onlyRemoveTypeImports": true,
|
||||||
}
|
"optimizeConstEnums": false,
|
||||||
`);
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
(process.env.BABEL_8_BREAKING ? describe.skip : describe)("Babel 7", () => {
|
(process.env.BABEL_8_BREAKING ? describe.skip : describe)("Babel 7", () => {
|
||||||
@ -78,16 +79,17 @@ describe("normalize options", () => {
|
|||||||
);
|
);
|
||||||
it("default values", () => {
|
it("default values", () => {
|
||||||
expect(normalizeOptions({})).toMatchInlineSnapshot(`
|
expect(normalizeOptions({})).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"allExtensions": false,
|
"allExtensions": false,
|
||||||
"allowNamespaces": true,
|
"allowNamespaces": true,
|
||||||
"isTSX": false,
|
"disallowAmbiguousJSXLike": false,
|
||||||
"jsxPragma": undefined,
|
"isTSX": false,
|
||||||
"jsxPragmaFrag": "React.Fragment",
|
"jsxPragma": undefined,
|
||||||
"onlyRemoveTypeImports": undefined,
|
"jsxPragmaFrag": "React.Fragment",
|
||||||
"optimizeConstEnums": false,
|
"onlyRemoveTypeImports": undefined,
|
||||||
}
|
"optimizeConstEnums": false,
|
||||||
`);
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2021,6 +2021,7 @@ __metadata:
|
|||||||
resolution: "@babel/plugin-syntax-typescript@workspace:packages/babel-plugin-syntax-typescript"
|
resolution: "@babel/plugin-syntax-typescript@workspace:packages/babel-plugin-syntax-typescript"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/core": "workspace:^"
|
"@babel/core": "workspace:^"
|
||||||
|
"@babel/helper-plugin-test-runner": "workspace:^"
|
||||||
"@babel/helper-plugin-utils": "workspace:^"
|
"@babel/helper-plugin-utils": "workspace:^"
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
"@babel/core": ^7.0.0-0
|
"@babel/core": ^7.0.0-0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user