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

feat(parser): add onInsertedSemicolon option #252

Merged
merged 1 commit into from Mar 5, 2024

Conversation

dmichon-msft
Copy link

@dmichon-msft dmichon-msft commented Mar 4, 2024

Adds support for the onInsertedSemicolon callback option, matching the base behavior of the acorn option of the same name. This option is used by webpack to identify when replacing the text of a node with a parenthesized expression would run afoul of a difference in runtime behavior if automatic semicolon insertion occurred.

Motivating example:

console.log('hi!') // ASI occurs here
foo() // ASI occurs here
console.log(foo.name)

If webpack replaces foo with the imported expression (0,some_module.foo), the resulting code has the runtime behavior of

console.log('hi!')(0,some_module.foo)() // tried to call the result of `console.log`, TypeError
console.log((0,some_module.foo).name) // Correct code

On the other hand, if webpack tries to always insert a semicolon, we instead have

console.log('hi') // ASI not needed
;(0,some_module.foo)() // Correct code
console.log(;(0,some_module.foo).name) // Syntax error

Ultimately this is an issue because webpack doesn't perform all transforms on the AST layer and run the code through a printer for performance reasons.

The lack of this option is the one difference in behavior between acorn and meriyah that would potentially impact using meriyah in webpack for a 20-30% AST parse performance boost.

Adds a basic unit test for the feature.

@3cp
Copy link
Member

3cp commented Mar 5, 2024

The change looks trivial! Glad it's easy to meet your requirement.

@3cp 3cp merged commit f7fc112 into meriyah:master Mar 5, 2024
3 checks passed
@3cp
Copy link
Member

3cp commented Mar 5, 2024

v4.4.0 is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants