Skip to content

Commit 7b4af43

Browse files
authored
feat(es/parser): Enable ergonomic brand checks for TypeScript (#2562)
1 parent 303cecb commit 7b4af43

File tree

5 files changed

+103
-9
lines changed

5 files changed

+103
-9
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecmascript/parser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
77
license = "Apache-2.0/MIT"
88
name = "swc_ecma_parser"
99
repository = "https://github.com/swc-project/swc.git"
10-
version = "0.76.0"
10+
version = "0.76.1"
1111

1212
[package.metadata.docs.rs]
1313
all-features = true

ecmascript/parser/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl Syntax {
280280
Syntax::Es(EsConfig {
281281
private_in_object, ..
282282
}) => private_in_object,
283-
_ => false,
283+
Syntax::Typescript(_) => true,
284284
}
285285
}
286286

ecmascript/parser/tests/typescript/class/property-private/input.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ class MyClass {
55
constructor() {
66
this.#b = "test";
77
}
8+
9+
method() {
10+
return #a in this;
11+
}
812
}

ecmascript/parser/tests/typescript/class/property-private/input.ts.json

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "Script",
33
"span": {
44
"start": 0,
5-
"end": 98,
5+
"end": 147,
66
"ctxt": 0
77
},
88
"body": [
@@ -21,7 +21,7 @@
2121
"declare": false,
2222
"span": {
2323
"start": 0,
24-
"end": 98,
24+
"end": 147,
2525
"ctxt": 0
2626
},
2727
"decorators": [],
@@ -220,6 +220,96 @@
220220
},
221221
"accessibility": null,
222222
"isOptional": false
223+
},
224+
{
225+
"type": "ClassMethod",
226+
"span": {
227+
"start": 102,
228+
"end": 145,
229+
"ctxt": 0
230+
},
231+
"key": {
232+
"type": "Identifier",
233+
"span": {
234+
"start": 102,
235+
"end": 108,
236+
"ctxt": 0
237+
},
238+
"value": "method",
239+
"optional": false
240+
},
241+
"function": {
242+
"params": [],
243+
"decorators": [],
244+
"span": {
245+
"start": 102,
246+
"end": 145,
247+
"ctxt": 0
248+
},
249+
"body": {
250+
"type": "BlockStatement",
251+
"span": {
252+
"start": 111,
253+
"end": 145,
254+
"ctxt": 0
255+
},
256+
"stmts": [
257+
{
258+
"type": "ReturnStatement",
259+
"span": {
260+
"start": 121,
261+
"end": 139,
262+
"ctxt": 0
263+
},
264+
"argument": {
265+
"type": "BinaryExpression",
266+
"span": {
267+
"start": 128,
268+
"end": 138,
269+
"ctxt": 0
270+
},
271+
"operator": "in",
272+
"left": {
273+
"type": "PrivateName",
274+
"span": {
275+
"start": 128,
276+
"end": 130,
277+
"ctxt": 0
278+
},
279+
"id": {
280+
"type": "Identifier",
281+
"span": {
282+
"start": 129,
283+
"end": 130,
284+
"ctxt": 0
285+
},
286+
"value": "a",
287+
"optional": false
288+
}
289+
},
290+
"right": {
291+
"type": "ThisExpression",
292+
"span": {
293+
"start": 134,
294+
"end": 138,
295+
"ctxt": 0
296+
}
297+
}
298+
}
299+
}
300+
]
301+
},
302+
"generator": false,
303+
"async": false,
304+
"typeParameters": null,
305+
"returnType": null
306+
},
307+
"kind": "method",
308+
"isStatic": false,
309+
"accessibility": null,
310+
"isAbstract": false,
311+
"isOptional": false,
312+
"isOverride": false
223313
}
224314
],
225315
"superClass": null,

0 commit comments

Comments
 (0)