Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix property double assignment #26

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

<br>

## Surfly notes

We use meriyah directly from `dist/meriyah.umd.js`.
Therefore, after each change we need to compile updated version with `npm run bundle` and commit it.

## [Demo](https://meriyah.github.io/meriyah)

## Features
Expand Down
3 changes: 2 additions & 1 deletion dist/meriyah.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -8691,7 +8691,8 @@
if (parser.token === 537079928)
report(parser, 116);
value = parsePrimaryExpression(parser, context | 16384, 2, 0, 1, 0, 0, 1, tokenPos, linePos, colPos);
if ((parser.token & 1073741824) !== 1073741824) {
if ((parser.token & 1073741824) !== 1073741824 ||
(parser.token & 4194304) === 4194304) {
value = parseMemberOrUpdateExpression(parser, context | 16384, value, 0, 0, tokenPos, linePos, colPos);
value = parseAssignmentExpression(parser, context | 16384, 0, 0, tokenPos, linePos, colPos, value);
if (parser.token === 18) {
Expand Down
5 changes: 4 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8709,7 +8709,10 @@ export function parsePropertyDefinition(
colPos
);

if ((parser.token & Token.IsClassField) !== Token.IsClassField) {
if (
(parser.token & Token.IsClassField) !== Token.IsClassField ||
(parser.token & Token.IsAssignOp) === Token.IsAssignOp
) {
value = parseMemberOrUpdateExpression(
parser,
context | Context.InClass,
Expand Down
146 changes: 146 additions & 0 deletions test/parser/next/public-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,152 @@ describe('Next - Public fields', () => {
end: 16,
range: [0, 16]
}
],
[
`class A { a = b = c }`,
Context.OptionsNext | Context.OptionsRanges,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ClassDeclaration',
decorators: [],
id: {
type: 'Identifier',
name: 'A',
start: 6,
end: 7,
range: [6, 7]
},
superClass: null,
body: {
type: 'ClassBody',
body: [
{
type: 'PropertyDefinition',
decorators: [],
key: {
type: 'Identifier',
name: 'a',
start: 10,
end: 11,
range: [10, 11]
},
value: {
type: 'AssignmentExpression',
operator: '=',
start: 14,
end: 19,
range: [14, 19],
left: {
type: 'Identifier',
name: 'b',
start: 14,
end: 15,
range: [14, 15]
},
right: {
type: 'Identifier',
name: 'c',
start: 18,
end: 19,
range: [18, 19]
}
},
computed: false,
static: false,
start: 10,
end: 19,
range: [10, 19]
}
],
start: 8,
end: 21,
range: [8, 21]
},
start: 0,
end: 21,
range: [0, 21]
}
],
start: 0,
end: 21,
range: [0, 21]
}
],
[
`class A { a = b += c }`,
Context.OptionsNext | Context.OptionsRanges,
{
body: [
{
body: {
body: [
{
computed: false,
decorators: [],
end: 20,
key: {
end: 11,
name: 'a',
range: [10, 11],
start: 10,
type: 'Identifier'
},
range: [10, 20],
start: 10,
static: false,
type: 'PropertyDefinition',
value: {
end: 20,
left: {
end: 15,
name: 'b',
range: [14, 15],
start: 14,
type: 'Identifier'
},
operator: '+=',
range: [14, 20],
right: {
end: 20,
name: 'c',
range: [19, 20],
start: 19,
type: 'Identifier'
},
start: 14,
type: 'AssignmentExpression'
}
}
],
end: 22,
range: [8, 22],
start: 8,
type: 'ClassBody'
},
decorators: [],
end: 22,
id: {
end: 7,
name: 'A',
range: [6, 7],
start: 6,
type: 'Identifier'
},
range: [0, 22],
start: 0,
superClass: null,
type: 'ClassDeclaration'
}
],
end: 22,
range: [0, 22],
sourceType: 'script',
start: 0,
type: 'Program'
}
]
]);
});
Loading