Skip to content

Commit

Permalink
Enable ergonomic brand checks (#priv in) by default (#13554)
Browse files Browse the repository at this point in the history
* Enable ergonomic brand checks by default in `@babel/parser`

* Enable ergonomic brand checks by default in `preset-env`

* Fix error position

* Update Babel 8 tests
  • Loading branch information
nicolo-ribaudo committed Aug 3, 2021
1 parent 5f4b58f commit a254ea3
Show file tree
Hide file tree
Showing 180 changed files with 281 additions and 61 deletions.
8 changes: 6 additions & 2 deletions packages/babel-compat-data/scripts/data/plugin-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ const es2021 = {
"proposal-logical-assignment-operators": "Logical Assignment",
};

const shippedProposal = {
"proposal-class-static-block": "Class static initialization blocks",
const es2022 = {
"proposal-private-property-in-object":
"Ergonomic brand checks for private fields",
"proposal-class-properties": {
Expand All @@ -149,10 +148,15 @@ const shippedProposal = {
"proposal-private-methods": "private class methods",
};

const shippedProposal = {
"proposal-class-static-block": "Class static initialization blocks",
};

// Run plugins for modern features first
module.exports = Object.assign(
{},
shippedProposal,
es2022,
es2021,
es2020,
es2019,
Expand Down
10 changes: 3 additions & 7 deletions packages/babel-parser/src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,16 +1154,12 @@ export default class ExpressionParser extends LValParser {
// https://tc39.es/proposal-private-fields-in-in
// RelationalExpression [In, Yield, Await]
// [+In] PrivateIdentifier in ShiftExpression[?Yield, ?Await]
const start = this.state.start;
const value = this.state.value;
const { value, start } = this.state;
node = this.parsePrivateName();
if (this.match(tt._in)) {
this.expectPlugin("privateIn");
this.classScope.usePrivateName(value, node.start);
} else if (this.hasPlugin("privateIn")) {
this.raise(this.state.start, Errors.PrivateInExpectedIn, value);
this.classScope.usePrivateName(value, start);
} else {
throw this.unexpected(start);
this.raise(start, Errors.PrivateInExpectedIn, value);
}
return node;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (3:3)"
}
"throws": "Unexpected token (3:9)"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"type": "File",
"start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
"errors": [
"SyntaxError: Private names are only allowed in property accesses (`obj.#x`) or in `in` expressions (`#x in obj`). (4:11)"
],
"program": {
"type": "Program",
"start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
"id": {
"type": "Identifier",
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"},
"name": "Foo"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start":10,"end":56,"loc":{"start":{"line":1,"column":10},"end":{"line":6,"column":1}},
"body": [
{
"type": "ClassPrivateProperty",
"start":14,"end":17,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5}},
"static": false,
"key": {
"type": "PrivateName",
"start":14,"end":16,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":4}},
"id": {
"type": "Identifier",
"start":15,"end":16,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4},"identifierName":"x"},
"name": "x"
}
},
"value": null
},
{
"type": "ClassMethod",
"start":20,"end":54,"loc":{"start":{"line":3,"column":2},"end":{"line":5,"column":3}},
"static": false,
"key": {
"type": "Identifier",
"start":20,"end":31,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":13},"identifierName":"constructor"},
"name": "constructor"
},
"computed": false,
"kind": "constructor",
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":34,"end":54,"loc":{"start":{"line":3,"column":16},"end":{"line":5,"column":3}},
"body": [
{
"type": "ExpressionStatement",
"start":40,"end":50,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":14}},
"expression": {
"type": "UnaryExpression",
"start":40,"end":49,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":13}},
"operator": "delete",
"prefix": true,
"argument": {
"type": "PrivateName",
"start":47,"end":49,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":13}},
"id": {
"type": "Identifier",
"start":48,"end":49,"loc":{"start":{"line":4,"column":12},"end":{"line":4,"column":13},"identifierName":"x"},
"name": "x"
}
}
}
}
],
"directives": []
}
}
]
}
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": ["estree", "privateIn"]
"plugins": ["estree"]
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
"errors": [
"SyntaxError: Private names are only allowed in property accesses (`obj.#x`) or in `in` expressions (`#x in obj`). (4:7)"
"SyntaxError: Private names are only allowed in property accesses (`obj.#x`) or in `in` expressions (`#x in obj`). (4:4)"
],
"program": {
"type": "Program",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
"errors": [
"SyntaxError: Private names are only allowed in property accesses (`obj.#x`) or in `in` expressions (`#x in obj`). (4:10)"
"SyntaxError: Private names are only allowed in property accesses (`obj.#x`) or in `in` expressions (`#x in obj`). (4:8)"
],
"program": {
"type": "Program",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
"errors": [
"SyntaxError: Private names are only allowed in property accesses (`obj.#x`) or in `in` expressions (`#x in obj`). (4:6)"
"SyntaxError: Private names are only allowed in property accesses (`obj.#x`) or in `in` expressions (`#x in obj`). (4:4)"
],
"program": {
"type": "Program",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
"errors": [
"SyntaxError: Private names are only allowed in property accesses (`obj.#x`) or in `in` expressions (`#x in obj`). (4:7)"
"SyntaxError: Private names are only allowed in property accesses (`obj.#x`) or in `in` expressions (`#x in obj`). (4:5)"
],
"program": {
"type": "Program",
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion packages/babel-parser/typings/babel-parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export type ParserPlugin =
| "partialApplication"
| "pipelineOperator"
| "placeholders"
| "privateIn"
| "privateIn" // Enabled by default
| "throwExpressions"
| "topLevelAwait"
| "typescript"
Expand Down
1 change: 0 additions & 1 deletion packages/babel-preset-env/data/shipped-proposals.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

const proposalPlugins = new Set([
"proposal-class-static-block",
"proposal-private-property-in-object",
]);

// use intermediary object to enforce alphabetical key order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { android, chrome < 91, edge, firefox < 90, ios, node, opera, safari, samsung }
proposal-class-properties { android, chrome < 84, edge < 84, firefox < 90, ios, node < 14.6, opera < 70, safari < 15, samsung }
proposal-private-methods { android, chrome < 84, edge < 84, firefox < 90, ios, node < 14.6, opera < 70, safari < 15, samsung }
proposal-numeric-separator { android, chrome < 75, edge < 79, firefox < 70, ios < 13, opera < 62, safari < 13, samsung < 11 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { android, chrome < 91, edge, firefox < 90, ios, node, opera, safari, samsung }
proposal-class-properties { android, chrome < 84, edge < 84, firefox < 90, ios, node < 14.6, opera < 70, safari < 15, samsung }
proposal-private-methods { android, chrome < 84, edge < 84, firefox < 90, ios, node < 14.6, opera < 70, safari < 15, samsung }
proposal-numeric-separator { android, chrome < 75, edge < 79, firefox < 70, ios < 13, opera < 62, safari < 13, samsung < 11 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { chrome < 91 }
proposal-class-properties { chrome < 84 }
proposal-private-methods { chrome < 84 }
proposal-numeric-separator { chrome < 75 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { chrome < 91 }
proposal-class-properties { chrome < 84 }
proposal-private-methods { chrome < 84 }
proposal-numeric-separator { chrome < 75 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { edge }
proposal-class-properties { edge < 84 }
proposal-private-methods { edge < 84 }
proposal-numeric-separator { edge < 79 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { edge }
proposal-class-properties { edge < 84 }
proposal-private-methods { edge < 84 }
proposal-numeric-separator { edge < 79 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { edge }
proposal-class-properties { edge < 84 }
proposal-private-methods { edge < 84 }
proposal-numeric-separator { edge < 79 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { edge }
proposal-class-properties { edge < 84 }
proposal-private-methods { edge < 84 }
proposal-numeric-separator { edge < 79 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { edge }
proposal-class-properties { edge < 84 }
proposal-private-methods { edge < 84 }
proposal-numeric-separator { edge < 79 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { edge }
proposal-class-properties { edge < 84 }
proposal-private-methods { edge < 84 }
proposal-numeric-separator { edge < 79 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { edge }
proposal-class-properties { edge < 84 }
proposal-private-methods { edge < 84 }
proposal-numeric-separator { edge < 79 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { edge }
proposal-class-properties { edge < 84 }
proposal-private-methods { edge < 84 }
proposal-numeric-separator { edge < 79 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { safari }
proposal-class-properties { safari < 15 }
proposal-private-methods { safari < 15 }
proposal-numeric-separator { safari < 13 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { safari }
proposal-class-properties { safari < 15 }
proposal-private-methods { safari < 15 }
proposal-numeric-separator { safari < 13 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { safari }
proposal-class-properties { safari < 15 }
proposal-private-methods { safari < 15 }
proposal-numeric-separator { safari < 13 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { safari }
proposal-class-properties { safari < 15 }
proposal-private-methods { safari < 15 }
proposal-numeric-separator { safari < 13 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { chrome < 91 }
syntax-class-properties
syntax-numeric-separator
syntax-nullish-coalescing-operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using targets:
Using modules transform: auto

Using plugins:
proposal-private-property-in-object { chrome < 91 }
syntax-class-properties
syntax-numeric-separator
syntax-nullish-coalescing-operator
Expand Down

0 comments on commit a254ea3

Please sign in to comment.