fix(es/parser): Consider ASI while parsing TypeScript type aliases (#8263)

**Related issue:**

 - Closes #8073.
This commit is contained in:
Donny/강동윤 2023-11-10 21:31:55 +09:00 committed by GitHub
parent e0525b595e
commit e58912622d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 359 additions and 38 deletions

View File

@ -1,6 +1,6 @@
var _class_private_field_get = require("@swc/helpers/_/_class_private_field_get"); var _class_private_field_get = require("@swc/helpers/_/_class_private_field_get");
var _class_private_field_init = require("@swc/helpers/_/_class_private_field_init"); var _class_private_field_init = require("@swc/helpers/_/_class_private_field_init");
var _x = /*#__PURE__*/ new WeakMap(); var _x = new WeakMap();
class Foo { class Foo {
test() { test() {
var _this, _this_y; var _this, _this_y;

View File

@ -1,6 +1,6 @@
var _class_private_field_get = require("@swc/helpers/_/_class_private_field_get"); var _class_private_field_get = require("@swc/helpers/_/_class_private_field_get");
var _class_private_field_init = require("@swc/helpers/_/_class_private_field_init"); var _class_private_field_init = require("@swc/helpers/_/_class_private_field_init");
var _x = /*#__PURE__*/ new WeakMap(); var _x = new WeakMap();
class Foo { class Foo {
test() { test() {
var _this, _this_y; var _this, _this_y;

View File

@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es2022",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": "unknown"
}

View File

@ -0,0 +1,8 @@
avplay.setListener({
onsubtitlechange: (duration, subtitles, type, attributes) => {
duration // $ExpectType string
subtitles // $ExpectType string
type // $ExpectType string
attributes // $ExpectType AVPlaySubtitleAttribute[]
}
})

View File

@ -0,0 +1,8 @@
avplay.setListener({
onsubtitlechange: (duration, subtitles, type, attributes)=>{
duration;
subtitles;
type;
attributes;
}
});

View File

@ -1,7 +1,7 @@
import { jsx as _jsx } from "react/jsx-runtime"; import { jsx as _jsx } from "react/jsx-runtime";
export const IconSpecHotkey = (param)=>{ export const IconSpecHotkey = (param)=>{
let { icon } = param; let { icon } = param;
return /*#__PURE__*/ _jsx("div", { return _jsx("div", {
children: icon children: icon
}); });
}; };

View File

@ -1,7 +1,7 @@
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime"; import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
const Component = ()=>{ const Component = ()=>{
return /*#__PURE__*/ _jsxDEV("p", { return _jsxDEV("p", {
thing: /*#__PURE__*/ _jsxDEV("a", {}, void 0, false, { thing: _jsxDEV("a", {}, void 0, false, {
fileName: "$DIR/tests/fixture/issues-8xxx/8210/input/1.js", fileName: "$DIR/tests/fixture/issues-8xxx/8210/input/1.js",
lineNumber: 2, lineNumber: 2,
columnNumber: 23 columnNumber: 23

View File

@ -2581,7 +2581,7 @@ impl<I: Tokens> Parser<I> {
} }
"type" => { "type" => {
if next || is!(self, IdentRef) { if next || (!self.input.had_line_break_before_cur() && is!(self, IdentRef)) {
if next { if next {
bump!(self); bump!(self);
} }

View File

@ -106,14 +106,39 @@
] ]
}, },
{ {
"type": "TsTypeAliasDeclaration", "type": "ExpressionStatement",
"span": { "span": {
"start": 34, "start": 34,
"end": 38,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 34,
"end": 38,
"ctxt": 0
},
"value": "type",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 39,
"end": 52, "end": 52,
"ctxt": 0 "ctxt": 0
}, },
"declare": false, "expression": {
"id": { "type": "AssignmentExpression",
"span": {
"start": 39,
"end": 51,
"ctxt": 0
},
"operator": "=",
"left": {
"type": "Identifier", "type": "Identifier",
"span": { "span": {
"start": 39, "start": 39,
@ -121,17 +146,19 @@
"ctxt": 0 "ctxt": 0
}, },
"value": "Foo", "value": "Foo",
"optional": false "optional": false,
"typeAnnotation": null
}, },
"typeParams": null, "right": {
"typeAnnotation": { "type": "Identifier",
"type": "TsKeywordType",
"span": { "span": {
"start": 45, "start": 45,
"end": 51, "end": 51,
"ctxt": 0 "ctxt": 0
}, },
"kind": "string" "value": "string",
"optional": false
}
} }
} }
], ],

View File

@ -133,14 +133,39 @@
}, },
"body": [ "body": [
{ {
"type": "TsTypeAliasDeclaration", "type": "ExpressionStatement",
"span": { "span": {
"start": 60, "start": 60,
"end": 64,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 60,
"end": 64,
"ctxt": 0
},
"value": "type",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 69,
"end": 82, "end": 82,
"ctxt": 0 "ctxt": 0
}, },
"declare": false, "expression": {
"id": { "type": "AssignmentExpression",
"span": {
"start": 69,
"end": 81,
"ctxt": 0
},
"operator": "=",
"left": {
"type": "Identifier", "type": "Identifier",
"span": { "span": {
"start": 69, "start": 69,
@ -148,17 +173,19 @@
"ctxt": 0 "ctxt": 0
}, },
"value": "Foo", "value": "Foo",
"optional": false "optional": false,
"typeAnnotation": null
}, },
"typeParams": null, "right": {
"typeAnnotation": { "type": "Identifier",
"type": "TsKeywordType",
"span": { "span": {
"start": 75, "start": 75,
"end": 81, "end": 81,
"ctxt": 0 "ctxt": 0
}, },
"kind": "string" "value": "string",
"optional": false
}
} }
} }
] ]

View File

@ -0,0 +1,8 @@
avplay.setListener({
onsubtitlechange: (duration, subtitles, type, attributes) => {
duration // $ExpectType string
subtitles // $ExpectType string
type // $ExpectType string
attributes // $ExpectType AVPlaySubtitleAttribute[]
}
})

View File

@ -0,0 +1,224 @@
{
"type": "Script",
"span": {
"start": 1,
"end": 271,
"ctxt": 0
},
"body": [
{
"type": "ExpressionStatement",
"span": {
"start": 1,
"end": 271,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 1,
"end": 271,
"ctxt": 0
},
"callee": {
"type": "MemberExpression",
"span": {
"start": 1,
"end": 19,
"ctxt": 0
},
"object": {
"type": "Identifier",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
},
"value": "avplay",
"optional": false
},
"property": {
"type": "Identifier",
"span": {
"start": 8,
"end": 19,
"ctxt": 0
},
"value": "setListener",
"optional": false
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "ObjectExpression",
"span": {
"start": 20,
"end": 270,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 26,
"end": 42,
"ctxt": 0
},
"value": "onsubtitlechange",
"optional": false
},
"value": {
"type": "ArrowFunctionExpression",
"span": {
"start": 44,
"end": 268,
"ctxt": 0
},
"params": [
{
"type": "Identifier",
"span": {
"start": 45,
"end": 53,
"ctxt": 0
},
"value": "duration",
"optional": false,
"typeAnnotation": null
},
{
"type": "Identifier",
"span": {
"start": 55,
"end": 64,
"ctxt": 0
},
"value": "subtitles",
"optional": false,
"typeAnnotation": null
},
{
"type": "Identifier",
"span": {
"start": 66,
"end": 70,
"ctxt": 0
},
"value": "type",
"optional": false,
"typeAnnotation": null
},
{
"type": "Identifier",
"span": {
"start": 72,
"end": 82,
"ctxt": 0
},
"value": "attributes",
"optional": false,
"typeAnnotation": null
}
],
"body": {
"type": "BlockStatement",
"span": {
"start": 87,
"end": 268,
"ctxt": 0
},
"stmts": [
{
"type": "ExpressionStatement",
"span": {
"start": 97,
"end": 105,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 97,
"end": 105,
"ctxt": 0
},
"value": "duration",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 136,
"end": 145,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 136,
"end": 145,
"ctxt": 0
},
"value": "subtitles",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 176,
"end": 180,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 176,
"end": 180,
"ctxt": 0
},
"value": "type",
"optional": false
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 211,
"end": 221,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 211,
"end": 221,
"ctxt": 0
},
"value": "attributes",
"optional": false
}
}
]
},
"async": false,
"generator": false,
"typeParameters": null,
"returnType": null
}
}
]
}
}
],
"typeArguments": null
}
}
],
"interpreter": null
}