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

Respect [no LineTerminator here] after nodes #16778

Merged
merged 3 commits into from
Aug 29, 2024

Conversation

nicolo-ribaudo
Copy link
Member

Q                       A
Fixed Issues? Fixes #16737
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

After this PR I'll open a followup to handle [no LineTerminator here] before nodes in a similar way, which simplifies its logic by a lot.

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: generator labels Aug 28, 2024
@babel-bot
Copy link
Collaborator

babel-bot commented Aug 28, 2024

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57774

@liuxingbaoyu
Copy link
Member

liuxingbaoyu commented Aug 28, 2024

This seems to cause duplicate parentheses when using createParenthesizedExpressions.
packages/babel-generator/test/fixtures/typescript/satisfies-parentheses/input.ts

@@ -731,7 +773,7 @@ class Printer {
this._printTrailingComments(node, parent);
this.token(")");
this._noLineTerminator = noLineTerminatorAfter;
exitInForStatementInit();
if (oldInForStatementInitWasTrue) this.inForStatementInit = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(feel free to ignore) Can we add a test to cover this line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Without this line it generates for (var a = (b = c) || d in e;;); instead of for (var a = (b = c) || (d in e);;);.

Copy link
Member

@liuxingbaoyu liuxingbaoyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thank you!

@nicolo-ribaudo nicolo-ribaudo merged commit 14e1873 into babel:main Aug 29, 2024
52 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the nlt-after-node branch August 29, 2024 11:04
zemnmez-renovate-bot added a commit to zemn-me/monorepo that referenced this pull request Oct 2, 2024
##### [`v7.25.7](https://github.com/babel/babel/blob/HEAD/CHANGELOG.md#v7257-2024-10-02)

##### 🐛 Bug Fix

-   `babel-helper-validator-identifier`
    -   [#16825](babel/babel#16825) fix: update identifier to unicode 16 ([@JLHwung](https://github.com/JLHwung))
-   `babel-traverse`
    -   [#16814](babel/babel#16814) fix: issue with node path keys updated on unrelated paths ([@DylanPiercey](https://github.com/DylanPiercey))
-   `babel-plugin-transform-classes`
    -   [#16797](babel/babel#16797) Use an inclusion rather than exclusion list for `super()` check ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
-   `babel-generator`
    -   [#16788](babel/babel#16788) Fix printing of TS `infer` in compact mode ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
    -   [#16785](babel/babel#16785) Print TS type annotations for destructuring in assignment pattern ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
    -   [#16778](babel/babel#16778) Respect `[no LineTerminator here]` after nodes ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))

##### 💅 Polish

-   `babel-types`
    -   [#16852](babel/babel#16852) Add deprecated JSDOC for fields ([@liuxingbaoyu](https://github.com/liuxingbaoyu))

##### 🏠 Internal

-   `babel-core`
    -   [#16820](babel/babel#16820) Allow sync loading of ESM when `--experimental-require-module` ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
-   `babel-helper-compilation-targets`, `babel-helper-plugin-utils`, `babel-preset-env`
    -   [#16858](babel/babel#16858) Add browserslist config to external dependency ([@JLHwung](https://github.com/JLHwung))
-   `babel-plugin-proposal-destructuring-private`, `babel-plugin-syntax-decimal`, `babel-plugin-syntax-import-reflection`, `babel-standalone`
    -   [#16809](babel/babel#16809) Archive syntax-import-reflection and syntax-decimal ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
-   `babel-generator`
    -   [#16779](babel/babel#16779) Simplify logic for `[no LineTerminator here]` before nodes ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))

##### 🏃‍♀️ Performance

-   `babel-plugin-transform-typescript`
    -   [#16875](babel/babel#16875) perf: Avoid extra cloning of namespaces ([@liuxingbaoyu](https://github.com/liuxingbaoyu))
-   `babel-types`
    -   [#16842](babel/babel#16842) perf: Improve [@babel/types](https://github.com/babel/types) builders ([@liuxingbaoyu](https://github.com/liuxingbaoyu))
    -   [#16828](babel/babel#16828) Only access `BABEL_TYPES_8_BREAKING` at startup ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
github-merge-queue bot pushed a commit to zemn-me/monorepo that referenced this pull request Oct 2, 2024
##### [`v7.25.7](https://github.com/babel/babel/blob/HEAD/CHANGELOG.md#v7257-2024-10-02)

##### 🐛 Bug Fix

-   `babel-helper-validator-identifier`
    -   [#16825](babel/babel#16825) fix: update identifier to unicode 16 ([@JLHwung](https://github.com/JLHwung))
-   `babel-traverse`
    -   [#16814](babel/babel#16814) fix: issue with node path keys updated on unrelated paths ([@DylanPiercey](https://github.com/DylanPiercey))
-   `babel-plugin-transform-classes`
    -   [#16797](babel/babel#16797) Use an inclusion rather than exclusion list for `super()` check ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
-   `babel-generator`
    -   [#16788](babel/babel#16788) Fix printing of TS `infer` in compact mode ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
    -   [#16785](babel/babel#16785) Print TS type annotations for destructuring in assignment pattern ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
    -   [#16778](babel/babel#16778) Respect `[no LineTerminator here]` after nodes ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))

##### 💅 Polish

-   `babel-types`
    -   [#16852](babel/babel#16852) Add deprecated JSDOC for fields ([@liuxingbaoyu](https://github.com/liuxingbaoyu))

##### 🏠 Internal

-   `babel-core`
    -   [#16820](babel/babel#16820) Allow sync loading of ESM when `--experimental-require-module` ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
-   `babel-helper-compilation-targets`, `babel-helper-plugin-utils`, `babel-preset-env`
    -   [#16858](babel/babel#16858) Add browserslist config to external dependency ([@JLHwung](https://github.com/JLHwung))
-   `babel-plugin-proposal-destructuring-private`, `babel-plugin-syntax-decimal`, `babel-plugin-syntax-import-reflection`, `babel-standalone`
    -   [#16809](babel/babel#16809) Archive syntax-import-reflection and syntax-decimal ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
-   `babel-generator`
    -   [#16779](babel/babel#16779) Simplify logic for `[no LineTerminator here]` before nodes ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))

##### 🏃‍♀️ Performance

-   `babel-plugin-transform-typescript`
    -   [#16875](babel/babel#16875) perf: Avoid extra cloning of namespaces ([@liuxingbaoyu](https://github.com/liuxingbaoyu))
-   `babel-types`
    -   [#16842](babel/babel#16842) perf: Improve [@babel/types](https://github.com/babel/types) builders ([@liuxingbaoyu](https://github.com/liuxingbaoyu))
    -   [#16828](babel/babel#16828) Only access `BABEL_TYPES_8_BREAKING` at startup ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Wrong logic for printing [no LineTerminator here] after arbitrary node
4 participants