Skip to content

Commit 7f2a2c1

Browse files
authored
refactor(es/ast): Improve type definitions of patterns (#8532)
**Description:** - Copy `AssignmentTarget` from `oxc`. - Use `BindingIdentifier` in more places. **Related issue:** - Closes #8026
1 parent 47e7b89 commit 7f2a2c1

File tree

369 files changed

+7824
-6987
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

369 files changed

+7824
-6987
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
let b;
2-
for(let i = 0; i < 2; ++i)b = 0 === i ? 1 : 2, console.log(0, b);
2+
for(let i = 0; i < 2; ++i)console.log(0, b = 0 === i ? 1 : 2);
33
let c = 1, d;
44
while(c--);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
let b, c, d;
2-
for(let i = 0; i < 2; ++i)b = 0 === i ? 1 : 2, console.log(0, b);
2+
for(let i = 0; i < 2; ++i)console.log(0, b = 0 === i ? 1 : 2);
33
c = 1;
44
while(c--);
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export var fn = function() {
2-
var varA;
3-
return(// a bad comment
4-
varA = condCheck ? "a" : "b", objCreator({
5-
varA: varA
6-
}));
2+
return objCreator({
3+
varA: condCheck ? // a bad comment
4+
"a" : "b"
5+
});
76
};

crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.1.normal.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ var Point = /*#__PURE__*/ function() {
77
this.x = x;
88
this.y = y;
99
}
10-
Point.Origin // unexpected error here bug 840246
11-
= function Origin() {
10+
Point.Origin = function Origin() {
1211
return {
1312
x: 0,
1413
y: 0
1514
};
16-
};
15+
} // unexpected error here bug 840246
16+
;
1717
return Point;
1818
}();
1919
(function(Point) {
@@ -31,13 +31,13 @@ var A;
3131
this.x = x;
3232
this.y = y;
3333
}
34-
Point.Origin // unexpected error here bug 840246
35-
= function Origin() {
34+
Point.Origin = function Origin() {
3635
return {
3736
x: 0,
3837
y: 0
3938
};
40-
};
39+
} // unexpected error here bug 840246
40+
;
4141
return Point;
4242
}();
4343
A.Point = Point;

crates/swc/tests/tsc-references/classAbstractSuperCalls.1.normal.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ var C = /*#__PURE__*/ function(B) {
4444
_proto.foo = function foo() {
4545
return 2;
4646
};
47-
_proto.qux // 2 errors, foo is abstract
48-
= function qux() {
47+
_proto.qux = function qux() {
4948
return _get(_get_prototype_of(C.prototype), "foo", this).call(this) || _get(_get_prototype_of(C.prototype), "foo", this);
50-
};
49+
} // 2 errors, foo is abstract
50+
;
5151
_proto.norf = function norf() {
5252
return _get(_get_prototype_of(C.prototype), "bar", this).call(this);
5353
};

crates/swc/tests/tsc-references/classConstructorAccessibility2.1.normal.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ var DerivedB = /*#__PURE__*/ function(BaseB1) {
7979
_proto.createInstance = function createInstance() {
8080
new DerivedB(7);
8181
};
82-
_proto.createBaseInstance // ok
83-
= function createBaseInstance() {
82+
_proto.createBaseInstance = function createBaseInstance() {
8483
new BaseB(8);
85-
};
86-
DerivedB.staticBaseInstance // ok
87-
= function staticBaseInstance() {
84+
} // ok
85+
;
86+
DerivedB.staticBaseInstance = function staticBaseInstance() {
8887
new BaseB(9);
89-
};
88+
} // ok
89+
;
9090
return DerivedB;
9191
}(BaseB);
9292
var DerivedC = /*#__PURE__*/ function(BaseC1) {
@@ -104,14 +104,14 @@ var DerivedC = /*#__PURE__*/ function(BaseC1) {
104104
_proto.createInstance = function createInstance() {
105105
new DerivedC(9);
106106
};
107-
_proto.createBaseInstance // error
108-
= function createBaseInstance() {
107+
_proto.createBaseInstance = function createBaseInstance() {
109108
new BaseC(10);
110-
};
111-
DerivedC.staticBaseInstance // error
112-
= function staticBaseInstance() {
109+
} // error
110+
;
111+
DerivedC.staticBaseInstance = function staticBaseInstance() {
113112
new BaseC(11);
114-
};
113+
} // error
114+
;
115115
return DerivedC;
116116
}(BaseC);
117117
var ba = new BaseA(1);

crates/swc/tests/tsc-references/classConstructorAccessibility5.1.normal.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ var Derived = /*#__PURE__*/ function(Base1) {
1414
_class_call_check(this, Derived);
1515
return _super.apply(this, arguments);
1616
}
17-
Derived.make // ok
18-
= function make() {
17+
Derived.make = function make() {
1918
new Base();
20-
};
19+
} // ok
20+
;
2121
return Derived;
2222
}(Base);
2323
var Unrelated = /*#__PURE__*/ function() {
2424
"use strict";
2525
function Unrelated() {
2626
_class_call_check(this, Unrelated);
2727
}
28-
Unrelated.fake // error
29-
= function fake() {
28+
Unrelated.fake = function fake() {
3029
new Base();
31-
};
30+
} // error
31+
;
3232
return Unrelated;
3333
}();

crates/swc/tests/tsc-references/computedPropertyNames11_ES5.2.minified.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//// [computedPropertyNames11_ES5.ts]
22
import { _ as _define_enumerable_properties } from "@swc/helpers/_/_define_enumerable_properties";
3-
var s, n, a, _mutatorMap = {};
4-
_mutatorMap[s] = _mutatorMap[s] || {}, _mutatorMap[s].get = function() {
3+
var s, n, a, _obj, _mutatorMap = {};
4+
_obj = {}, _mutatorMap[s] = _mutatorMap[s] || {}, _mutatorMap[s].get = function() {
55
return 0;
66
}, _mutatorMap[n] = _mutatorMap[n] || {}, _mutatorMap[n].set = function(v) {}, _mutatorMap[s + s] = _mutatorMap[s + s] || {}, _mutatorMap[s + s].get = function() {
77
return 0;
@@ -13,4 +13,4 @@ _mutatorMap[s] = _mutatorMap[s] || {}, _mutatorMap[s].get = function() {
1313
return 0;
1414
}, _mutatorMap["hello bye"] = _mutatorMap["hello bye"] || {}, _mutatorMap["hello bye"].set = function(v) {}, _mutatorMap["hello ".concat(a, " bye")] = _mutatorMap["hello ".concat(a, " bye")] || {}, _mutatorMap["hello ".concat(a, " bye")].get = function() {
1515
return 0;
16-
}, _define_enumerable_properties({}, _mutatorMap);
16+
}, _define_enumerable_properties(_obj, _mutatorMap);
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//// [computedPropertyNames1_ES5.ts]
22
import { _ as _define_enumerable_properties } from "@swc/helpers/_/_define_enumerable_properties";
3-
var _mutatorMap = {};
4-
_mutatorMap[1] = _mutatorMap[1] || {}, _mutatorMap[1].get = function() {
3+
var _obj, _mutatorMap = {};
4+
_obj = {}, _mutatorMap[1] = _mutatorMap[1] || {}, _mutatorMap[1].get = function() {
55
return 0;
6-
}, _mutatorMap[1] = _mutatorMap[1] || {}, _mutatorMap[1].set = function(v) {}, _define_enumerable_properties({}, _mutatorMap);
6+
}, _mutatorMap[1] = _mutatorMap[1] || {}, _mutatorMap[1].set = function(v) {}, _define_enumerable_properties(_obj, _mutatorMap);

crates/swc/tests/tsc-references/derivedClassTransitivity.1.normal.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var D = /*#__PURE__*/ function(C) {
2121
return _super.apply(this, arguments);
2222
}
2323
var _proto = D.prototype;
24-
_proto.foo // ok to drop parameters
25-
= function foo() {};
24+
_proto.foo = function foo() {} // ok to drop parameters
25+
;
2626
return D;
2727
}(C);
2828
var E = /*#__PURE__*/ function(D) {
@@ -34,8 +34,8 @@ var E = /*#__PURE__*/ function(D) {
3434
return _super.apply(this, arguments);
3535
}
3636
var _proto = E.prototype;
37-
_proto.foo // ok to add optional parameters
38-
= function foo(x) {};
37+
_proto.foo = function foo(x) {} // ok to add optional parameters
38+
;
3939
return E;
4040
}(D);
4141
var c;

crates/swc/tests/tsc-references/derivedClassTransitivity2.1.normal.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var D = /*#__PURE__*/ function(C) {
2121
return _super.apply(this, arguments);
2222
}
2323
var _proto = D.prototype;
24-
_proto.foo // ok to drop parameters
25-
= function foo(x) {};
24+
_proto.foo = function foo(x) {} // ok to drop parameters
25+
;
2626
return D;
2727
}(C);
2828
var E = /*#__PURE__*/ function(D) {
@@ -34,8 +34,8 @@ var E = /*#__PURE__*/ function(D) {
3434
return _super.apply(this, arguments);
3535
}
3636
var _proto = E.prototype;
37-
_proto.foo // ok to add optional parameters
38-
= function foo(x, y) {};
37+
_proto.foo = function foo(x, y) {} // ok to add optional parameters
38+
;
3939
return E;
4040
}(D);
4141
var c;

crates/swc/tests/tsc-references/derivedClassTransitivity3.1.normal.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var D = /*#__PURE__*/ function(C) {
2121
return _super.apply(this, arguments);
2222
}
2323
var _proto = D.prototype;
24-
_proto.foo // ok to drop parameters
25-
= function foo(x) {};
24+
_proto.foo = function foo(x) {} // ok to drop parameters
25+
;
2626
return D;
2727
}(C);
2828
var E = /*#__PURE__*/ function(D) {
@@ -34,8 +34,8 @@ var E = /*#__PURE__*/ function(D) {
3434
return _super.apply(this, arguments);
3535
}
3636
var _proto = E.prototype;
37-
_proto.foo // ok to add optional parameters
38-
= function foo(x, y) {};
37+
_proto.foo = function foo(x, y) {} // ok to add optional parameters
38+
;
3939
return E;
4040
}(D);
4141
var c;

crates/swc/tests/tsc-references/derivedClassTransitivity4.1.normal.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var D = /*#__PURE__*/ function(C) {
2121
return _super.apply(this, arguments);
2222
}
2323
var _proto = D.prototype;
24-
_proto.foo // ok to drop parameters
25-
= function foo() {};
24+
_proto.foo = function foo() {} // ok to drop parameters
25+
;
2626
return D;
2727
}(C);
2828
var E = /*#__PURE__*/ function(D) {
@@ -34,8 +34,8 @@ var E = /*#__PURE__*/ function(D) {
3434
return _super.apply(this, arguments);
3535
}
3636
var _proto = E.prototype;
37-
_proto.foo // ok to add optional parameters
38-
= function foo(x) {};
37+
_proto.foo = function foo(x) {} // ok to add optional parameters
38+
;
3939
return E;
4040
}(D);
4141
var c;

crates/swc/tests/tsc-references/genericCallWithObjectTypeArgsAndConstraints3.2.minified.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
33
import { _ as _inherits } from "@swc/helpers/_/_inherits";
44
import { _ as _create_super } from "@swc/helpers/_/_create_super";
5-
var Base = function Base() {
5+
var y, y1, Base = function Base() {
66
_class_call_check(this, Base);
77
}, Derived = function(Base) {
88
_inherits(Derived, Base);
@@ -19,4 +19,8 @@ var Base = function Base() {
1919
}
2020
return Derived2;
2121
}(Base);
22-
new Derived(), new Derived2(), new Derived(), new Derived2(), new Derived(), new Derived2(), new Base(), new Derived();
22+
new Derived(), new Derived2(), new Derived(), new Derived2(), new Derived(), new Derived2(), y = function(x) {
23+
return x;
24+
}, new Base(), y(null), y1 = function(x) {
25+
return x;
26+
}, new Derived(), y1(null);
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
//// [intersectionReduction.ts]
2-
ab.kind, x, f10(a1), f10(a2), ({
3-
a: "foo",
4-
b: 42
5-
})[k] = "bar", ({
6-
a: "foo",
7-
b: !0
8-
})[k] = "bar", s2 = s1 = s2, t2 = t1 = t2, shouldBeB;
2+
ab.kind, x, f10(a1), f10(a2), s2 = s1 = s2, t2 = t1 = t2, shouldBeB;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
//// [intersectionReductionStrict.ts]
2-
ab.kind, x, ({
3-
a: "foo",
4-
b: 42
5-
})[k] = "bar", ({
6-
a: "foo",
7-
b: !0
8-
})[k] = "bar", s2 = s1 = s2, t2 = t1 = t2;
2+
ab.kind, x, s2 = s1 = s2, t2 = t1 = t2;

crates/swc/tests/tsc-references/numericIndexerConstrainsPropertyDeclarations.1.normal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ var C = /*#__PURE__*/ function() {
1111
_proto.foo = function foo() {
1212
return "";
1313
};
14-
C.foo // ok
15-
= function foo() {};
14+
C.foo = function foo() {} // ok
15+
;
1616
_create_class(C, [
1717
{
1818
key: "X",
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//// [numericStringLiteralTypes.ts]
2-
var container1 = createContainer("hi"), container2 = createContainer(2);
32
f([
4-
container1,
5-
container2
3+
createContainer("hi"),
4+
createContainer(2)
65
], function(value1, value2) {});
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
//// [optionalChainingInference.ts]
2-
var b1 = {
2+
unbox({
33
value: null == su ? void 0 : su.length
4-
};
5-
unbox(b1);
6-
var b2 = {
4+
}), unbox({
75
value: null == su ? void 0 : su.length
8-
};
9-
unbox(b2);
10-
var b3 = {
6+
}), unbox({
117
value: null == su ? void 0 : su.length
12-
};
13-
unbox(b3);
14-
var b4 = {
8+
}), unbox({
159
value: null == fnu ? void 0 : fnu()
16-
};
17-
unbox(b4);
18-
var b5 = {
10+
}), unbox({
1911
value: null == su ? void 0 : su.length
20-
};
21-
unbox(b5);
22-
var b6 = {
12+
}), unbox({
2313
value: null == osu ? void 0 : osu.prop.length
24-
};
25-
unbox(b6);
26-
var b7 = {
14+
}), unbox({
2715
value: null == osu ? void 0 : osu.prop.length
28-
};
29-
unbox(b7);
30-
var b8 = {
16+
}), unbox({
3117
value: null == ofnu ? void 0 : ofnu.prop()
32-
};
33-
unbox(b8);
18+
});

crates/swc/tests/tsc-references/override2.1.normal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ var AD3 = /*#__PURE__*/ function(AB) {
3535
return _super.apply(this, arguments);
3636
}
3737
var _proto = AD3.prototype;
38-
_proto.foo // need override?
39-
= function foo(v) {};
38+
_proto.foo = function foo(v) {} // need override?
39+
;
4040
_proto.baz = function baz() {};
4141
return AD3;
4242
}(AB);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//// [parserES5ComputedPropertyName4.ts]
22
import { _ as _define_enumerable_properties } from "@swc/helpers/_/_define_enumerable_properties";
3-
var _mutatorMap = {};
4-
_mutatorMap[e] = _mutatorMap[e] || {}, _mutatorMap[e].get = function() {}, _define_enumerable_properties({}, _mutatorMap);
3+
var _obj, _mutatorMap = {};
4+
_obj = {}, _mutatorMap[e] = _mutatorMap[e] || {}, _mutatorMap[e].get = function() {}, _define_enumerable_properties(_obj, _mutatorMap);

crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11.1.normal.js

+6
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55
//! 1 | 1 >>= 2;
66
//! : ^
77
//! `----
8+
//!
9+
//! x Invalid assignment target
10+
//! ,----
11+
//! 1 | 1 >>= 2;
12+
//! : ^
13+
//! `----

crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11.2.minified.js

+6
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55
//! 1 | 1 >>= 2;
66
//! : ^
77
//! `----
8+
//!
9+
//! x Invalid assignment target
10+
//! ,----
11+
//! 1 | 1 >>= 2;
12+
//! : ^
13+
//! `----

0 commit comments

Comments
 (0)