-
Notifications
You must be signed in to change notification settings - Fork 735
Fix leading source file comment emit bugs #1945
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4384,18 +4384,24 @@ func (p *Printer) emitSourceFile(node *ast.SourceFile) { | |
|
|
||
| p.writeLine() | ||
|
|
||
| state := p.emitDetachedCommentsBeforeStatementList(node.AsNode(), node.Statements.Loc) | ||
| p.pushNameGenerationScope(node.AsNode()) | ||
| p.generateAllNames(node.Statements) | ||
|
|
||
| index := 0 | ||
| var state *commentState | ||
| if node.ScriptKind != core.ScriptKindJSON { | ||
| p.emitShebangIfNeeded(node) | ||
| index = p.emitPrologueDirectives(node.Statements) | ||
| if !p.writer.IsAtStartOfLine() { | ||
| p.writeLine() | ||
| } | ||
| state = p.emitDetachedCommentsBeforeStatementList(node.AsNode(), node.Statements.Loc) | ||
| p.emitHelpers(node.AsNode()) | ||
| if node.IsDeclarationFile { | ||
| p.emitTripleSlashDirectives(node) | ||
| } | ||
| } else { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think a JSON document will ever have detached leading comments (since it only ever has one statement and no prologues), so this could probably be a hardcoded initial empty comment emit state, but it's probably fine.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, no test change when I added this back (nil is fine), but since the original code did this unconditionally (both codebases) I thought I would add it back. I bet we just don't have any tests which reprint a JSON file without downleveling it... |
||
| state = p.emitDetachedCommentsBeforeStatementList(node.AsNode(), node.Statements.Loc) | ||
| } | ||
|
|
||
| // !!! Emit triple-slash directives | ||
|
|
@@ -5083,7 +5089,7 @@ func (p *Printer) emitDetachedCommentsBeforeStatementList(node *ast.Node, detach | |
| containerPos := p.containerPos | ||
| containerEnd := p.containerEnd | ||
| declarationListContainerEnd := p.declarationListContainerEnd | ||
| skipLeadingComments := emitFlags&EFNoLeadingComments == 0 && !ast.PositionIsSynthesized(detachedRange.Pos()) | ||
| skipLeadingComments := ast.PositionIsSynthesized(detachedRange.Pos()) || emitFlags&EFNoLeadingComments != 0 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a porting bug.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the ol' "let's invert this condition" and then fail to invert the usage/name. |
||
|
|
||
| if !skipLeadingComments { | ||
| p.emitDetachedCommentsAndUpdateCommentsInfo(detachedRange) | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,9 @@ | ||
| --- old.amdDependencyComment1.js | ||
| +++ new.amdDependencyComment1.js | ||
| @@= skipped -7, +7 lines =@@ | ||
|
|
||
| //// [amdDependencyComment1.js] | ||
| @@= skipped -9, +9 lines =@@ | ||
| "use strict"; | ||
| -///<amd-dependency path='bar'/> | ||
| ///<amd-dependency path='bar'/> | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| -var m1 = require("m2"); | ||
| +///<amd-dependency path='bar'/> | ||
| +const m1 = require("m2"); | ||
| m1.f(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required. I am not sure where Strada did this particular newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first line of
emitSourceFileis an unconditionalwriteLine, which is afterwriteFile'semitShebangIfNeededandemitPrologueDirectivesIfNeededcalls. Which puts this in exactly the right place.