-
Notifications
You must be signed in to change notification settings - Fork 25
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
'use strict' pushed below imports #5
Comments
Hi, thanks for the report. Can I ask, why are you including |
blutorange
added a commit
that referenced
this issue
Apr 18, 2022
The most important goal is correctness. Directives were destroyed by placing imports above it. Directive prologues are defined by the spec as > A Directive Prologue is the longest sequence of ExpressionStatements occurring as > the initial StatementListItems or ModuleItems of a FunctionBody, a ScriptBody, or > a ModuleBody and where each ExpressionStatement in the sequence consists entirely > of a StringLiteral token followed by a semicolon. The semicolon may appear explicitly > or may be inserted by automatic semicolon insertion (12.9). A Directive Prologue may > be an empty sequence.
blutorange
added a commit
that referenced
this issue
Apr 18, 2022
The comments are added back as part of the new directives placed at the top, so we should remove them from the original code we add after the directives and the imports.
IanVS
pushed a commit
that referenced
this issue
Apr 27, 2022
* Preserve directive prologues, fixes #5 The most important goal is correctness. Directives were destroyed by placing imports above it. Directive prologues are defined by the spec as > A Directive Prologue is the longest sequence of ExpressionStatements occurring as > the initial StatementListItems or ModuleItems of a FunctionBody, a ScriptBody, or > a ModuleBody and where each ExpressionStatement in the sequence consists entirely > of a StringLiteral token followed by a semicolon. The semicolon may appear explicitly > or may be inserted by automatic semicolon insertion (12.9). A Directive Prologue may > be an empty sequence. * Remove nodes from code via proper algorithm, fixes #7 Previously, a regex string replacement was used, and regex is an inadequate tool for transforming entire JavaScript code files. Instead, this commit changes that to a proper algorithm that removes the code at the source position ranges of the nodes to be removed. This will not work properly if the Babel parser ever did not return the correct source positions, but that is not a regression since the former algortihm already relied on the positions being correct. * Remove comments from directives we add back at the top, #5 The comments are added back as part of the new directives placed at the top, so we should remove them from the original code we add after the directives and the imports.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your Environment
Describe the bug
'use strict'
is pushed below imports.To Reproduce
Expected behavior
Keep
'use strict'
above.Screenshots, code sample, etc
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
Error log
Contribute to @trivago/prettier-plugin-sort-imports
The text was updated successfully, but these errors were encountered: