Skip to content

Commit

Permalink
refactor(es/ast): Improve type definitions of patterns (#8532)
Browse files Browse the repository at this point in the history
**Description:**

 - Copy `AssignmentTarget` from `oxc`.
 - Use `BindingIdentifier` in more places.

**Related issue:**
 
 - Closes #8026
  • Loading branch information
kdy1 authored Feb 5, 2024
1 parent 47e7b89 commit 7f2a2c1
Show file tree
Hide file tree
Showing 369 changed files with 7,824 additions and 6,987 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let b;
for(let i = 0; i < 2; ++i)b = 0 === i ? 1 : 2, console.log(0, b);
for(let i = 0; i < 2; ++i)console.log(0, b = 0 === i ? 1 : 2);
let c = 1, d;
while(c--);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let b, c, d;
for(let i = 0; i < 2; ++i)b = 0 === i ? 1 : 2, console.log(0, b);
for(let i = 0; i < 2; ++i)console.log(0, b = 0 === i ? 1 : 2);
c = 1;
while(c--);
9 changes: 4 additions & 5 deletions crates/swc/tests/fixture/issues-8xxx/8412/output/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export var fn = function() {
var varA;
return(// a bad comment
varA = condCheck ? "a" : "b", objCreator({
varA: varA
}));
return objCreator({
varA: condCheck ? // a bad comment
"a" : "b"
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ var Point = /*#__PURE__*/ function() {
this.x = x;
this.y = y;
}
Point.Origin // unexpected error here bug 840246
= function Origin() {
Point.Origin = function Origin() {
return {
x: 0,
y: 0
};
};
} // unexpected error here bug 840246
;
return Point;
}();
(function(Point) {
Expand All @@ -31,13 +31,13 @@ var A;
this.x = x;
this.y = y;
}
Point.Origin // unexpected error here bug 840246
= function Origin() {
Point.Origin = function Origin() {
return {
x: 0,
y: 0
};
};
} // unexpected error here bug 840246
;
return Point;
}();
A.Point = Point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ var C = /*#__PURE__*/ function(B) {
_proto.foo = function foo() {
return 2;
};
_proto.qux // 2 errors, foo is abstract
= function qux() {
_proto.qux = function qux() {
return _get(_get_prototype_of(C.prototype), "foo", this).call(this) || _get(_get_prototype_of(C.prototype), "foo", this);
};
} // 2 errors, foo is abstract
;
_proto.norf = function norf() {
return _get(_get_prototype_of(C.prototype), "bar", this).call(this);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ var DerivedB = /*#__PURE__*/ function(BaseB1) {
_proto.createInstance = function createInstance() {
new DerivedB(7);
};
_proto.createBaseInstance // ok
= function createBaseInstance() {
_proto.createBaseInstance = function createBaseInstance() {
new BaseB(8);
};
DerivedB.staticBaseInstance // ok
= function staticBaseInstance() {
} // ok
;
DerivedB.staticBaseInstance = function staticBaseInstance() {
new BaseB(9);
};
} // ok
;
return DerivedB;
}(BaseB);
var DerivedC = /*#__PURE__*/ function(BaseC1) {
Expand All @@ -104,14 +104,14 @@ var DerivedC = /*#__PURE__*/ function(BaseC1) {
_proto.createInstance = function createInstance() {
new DerivedC(9);
};
_proto.createBaseInstance // error
= function createBaseInstance() {
_proto.createBaseInstance = function createBaseInstance() {
new BaseC(10);
};
DerivedC.staticBaseInstance // error
= function staticBaseInstance() {
} // error
;
DerivedC.staticBaseInstance = function staticBaseInstance() {
new BaseC(11);
};
} // error
;
return DerivedC;
}(BaseC);
var ba = new BaseA(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ var Derived = /*#__PURE__*/ function(Base1) {
_class_call_check(this, Derived);
return _super.apply(this, arguments);
}
Derived.make // ok
= function make() {
Derived.make = function make() {
new Base();
};
} // ok
;
return Derived;
}(Base);
var Unrelated = /*#__PURE__*/ function() {
"use strict";
function Unrelated() {
_class_call_check(this, Unrelated);
}
Unrelated.fake // error
= function fake() {
Unrelated.fake = function fake() {
new Base();
};
} // error
;
return Unrelated;
}();
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [computedPropertyNames11_ES5.ts]
import { _ as _define_enumerable_properties } from "@swc/helpers/_/_define_enumerable_properties";
var s, n, a, _mutatorMap = {};
_mutatorMap[s] = _mutatorMap[s] || {}, _mutatorMap[s].get = function() {
var s, n, a, _obj, _mutatorMap = {};
_obj = {}, _mutatorMap[s] = _mutatorMap[s] || {}, _mutatorMap[s].get = function() {
return 0;
}, _mutatorMap[n] = _mutatorMap[n] || {}, _mutatorMap[n].set = function(v) {}, _mutatorMap[s + s] = _mutatorMap[s + s] || {}, _mutatorMap[s + s].get = function() {
return 0;
Expand All @@ -13,4 +13,4 @@ _mutatorMap[s] = _mutatorMap[s] || {}, _mutatorMap[s].get = function() {
return 0;
}, _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() {
return 0;
}, _define_enumerable_properties({}, _mutatorMap);
}, _define_enumerable_properties(_obj, _mutatorMap);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//// [computedPropertyNames1_ES5.ts]
import { _ as _define_enumerable_properties } from "@swc/helpers/_/_define_enumerable_properties";
var _mutatorMap = {};
_mutatorMap[1] = _mutatorMap[1] || {}, _mutatorMap[1].get = function() {
var _obj, _mutatorMap = {};
_obj = {}, _mutatorMap[1] = _mutatorMap[1] || {}, _mutatorMap[1].get = function() {
return 0;
}, _mutatorMap[1] = _mutatorMap[1] || {}, _mutatorMap[1].set = function(v) {}, _define_enumerable_properties({}, _mutatorMap);
}, _mutatorMap[1] = _mutatorMap[1] || {}, _mutatorMap[1].set = function(v) {}, _define_enumerable_properties(_obj, _mutatorMap);
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var D = /*#__PURE__*/ function(C) {
return _super.apply(this, arguments);
}
var _proto = D.prototype;
_proto.foo // ok to drop parameters
= function foo() {};
_proto.foo = function foo() {} // ok to drop parameters
;
return D;
}(C);
var E = /*#__PURE__*/ function(D) {
Expand All @@ -34,8 +34,8 @@ var E = /*#__PURE__*/ function(D) {
return _super.apply(this, arguments);
}
var _proto = E.prototype;
_proto.foo // ok to add optional parameters
= function foo(x) {};
_proto.foo = function foo(x) {} // ok to add optional parameters
;
return E;
}(D);
var c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var D = /*#__PURE__*/ function(C) {
return _super.apply(this, arguments);
}
var _proto = D.prototype;
_proto.foo // ok to drop parameters
= function foo(x) {};
_proto.foo = function foo(x) {} // ok to drop parameters
;
return D;
}(C);
var E = /*#__PURE__*/ function(D) {
Expand All @@ -34,8 +34,8 @@ var E = /*#__PURE__*/ function(D) {
return _super.apply(this, arguments);
}
var _proto = E.prototype;
_proto.foo // ok to add optional parameters
= function foo(x, y) {};
_proto.foo = function foo(x, y) {} // ok to add optional parameters
;
return E;
}(D);
var c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var D = /*#__PURE__*/ function(C) {
return _super.apply(this, arguments);
}
var _proto = D.prototype;
_proto.foo // ok to drop parameters
= function foo(x) {};
_proto.foo = function foo(x) {} // ok to drop parameters
;
return D;
}(C);
var E = /*#__PURE__*/ function(D) {
Expand All @@ -34,8 +34,8 @@ var E = /*#__PURE__*/ function(D) {
return _super.apply(this, arguments);
}
var _proto = E.prototype;
_proto.foo // ok to add optional parameters
= function foo(x, y) {};
_proto.foo = function foo(x, y) {} // ok to add optional parameters
;
return E;
}(D);
var c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var D = /*#__PURE__*/ function(C) {
return _super.apply(this, arguments);
}
var _proto = D.prototype;
_proto.foo // ok to drop parameters
= function foo() {};
_proto.foo = function foo() {} // ok to drop parameters
;
return D;
}(C);
var E = /*#__PURE__*/ function(D) {
Expand All @@ -34,8 +34,8 @@ var E = /*#__PURE__*/ function(D) {
return _super.apply(this, arguments);
}
var _proto = E.prototype;
_proto.foo // ok to add optional parameters
= function foo(x) {};
_proto.foo = function foo(x) {} // ok to add optional parameters
;
return E;
}(D);
var c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _inherits } from "@swc/helpers/_/_inherits";
import { _ as _create_super } from "@swc/helpers/_/_create_super";
var Base = function Base() {
var y, y1, Base = function Base() {
_class_call_check(this, Base);
}, Derived = function(Base) {
_inherits(Derived, Base);
Expand All @@ -19,4 +19,8 @@ var Base = function Base() {
}
return Derived2;
}(Base);
new Derived(), new Derived2(), new Derived(), new Derived2(), new Derived(), new Derived2(), new Base(), new Derived();
new Derived(), new Derived2(), new Derived(), new Derived2(), new Derived(), new Derived2(), y = function(x) {
return x;
}, new Base(), y(null), y1 = function(x) {
return x;
}, new Derived(), y1(null);
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
//// [intersectionReduction.ts]
ab.kind, x, f10(a1), f10(a2), ({
a: "foo",
b: 42
})[k] = "bar", ({
a: "foo",
b: !0
})[k] = "bar", s2 = s1 = s2, t2 = t1 = t2, shouldBeB;
ab.kind, x, f10(a1), f10(a2), s2 = s1 = s2, t2 = t1 = t2, shouldBeB;
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
//// [intersectionReductionStrict.ts]
ab.kind, x, ({
a: "foo",
b: 42
})[k] = "bar", ({
a: "foo",
b: !0
})[k] = "bar", s2 = s1 = s2, t2 = t1 = t2;
ab.kind, x, s2 = s1 = s2, t2 = t1 = t2;
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var C = /*#__PURE__*/ function() {
_proto.foo = function foo() {
return "";
};
C.foo // ok
= function foo() {};
C.foo = function foo() {} // ok
;
_create_class(C, [
{
key: "X",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//// [numericStringLiteralTypes.ts]
var container1 = createContainer("hi"), container2 = createContainer(2);
f([
container1,
container2
createContainer("hi"),
createContainer(2)
], function(value1, value2) {});
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
//// [optionalChainingInference.ts]
var b1 = {
unbox({
value: null == su ? void 0 : su.length
};
unbox(b1);
var b2 = {
}), unbox({
value: null == su ? void 0 : su.length
};
unbox(b2);
var b3 = {
}), unbox({
value: null == su ? void 0 : su.length
};
unbox(b3);
var b4 = {
}), unbox({
value: null == fnu ? void 0 : fnu()
};
unbox(b4);
var b5 = {
}), unbox({
value: null == su ? void 0 : su.length
};
unbox(b5);
var b6 = {
}), unbox({
value: null == osu ? void 0 : osu.prop.length
};
unbox(b6);
var b7 = {
}), unbox({
value: null == osu ? void 0 : osu.prop.length
};
unbox(b7);
var b8 = {
}), unbox({
value: null == ofnu ? void 0 : ofnu.prop()
};
unbox(b8);
});
4 changes: 2 additions & 2 deletions crates/swc/tests/tsc-references/override2.1.normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ var AD3 = /*#__PURE__*/ function(AB) {
return _super.apply(this, arguments);
}
var _proto = AD3.prototype;
_proto.foo // need override?
= function foo(v) {};
_proto.foo = function foo(v) {} // need override?
;
_proto.baz = function baz() {};
return AD3;
}(AB);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [parserES5ComputedPropertyName4.ts]
import { _ as _define_enumerable_properties } from "@swc/helpers/_/_define_enumerable_properties";
var _mutatorMap = {};
_mutatorMap[e] = _mutatorMap[e] || {}, _mutatorMap[e].get = function() {}, _define_enumerable_properties({}, _mutatorMap);
var _obj, _mutatorMap = {};
_obj = {}, _mutatorMap[e] = _mutatorMap[e] || {}, _mutatorMap[e].get = function() {}, _define_enumerable_properties(_obj, _mutatorMap);
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
//! 1 | 1 >>= 2;
//! : ^
//! `----
//!
//! x Invalid assignment target
//! ,----
//! 1 | 1 >>= 2;
//! : ^
//! `----
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
//! 1 | 1 >>= 2;
//! : ^
//! `----
//!
//! x Invalid assignment target
//! ,----
//! 1 | 1 >>= 2;
//! : ^
//! `----
Loading

0 comments on commit 7f2a2c1

Please sign in to comment.