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

[estree] attach comments after directives at the end of file #14920

Merged
merged 3 commits into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/babel-parser/src/plugins/estree.ts
Expand Up @@ -111,6 +111,9 @@ export default (superClass: typeof Parser) =>
// @ts-expect-error TS2339: Property 'raw' does not exist on type 'Undone '.
expression.raw = directiveLiteral.extra.raw;

stmt.leadingComments = directive.leadingComments?.slice();
stmt.trailingComments = directive.trailingComments?.slice();

stmt.expression = this.finishNodeAt(
expression,
"Literal",
Expand Down Expand Up @@ -175,6 +178,9 @@ export default (superClass: typeof Parser) =>
end,
afterBlockParse,
);
if (node.directives.length) {
this.processComment(node);
hegemonic marked this conversation as resolved.
Show resolved Hide resolved
}

const directiveStatements = node.directives.map(d =>
this.directiveToStmt(d),
Expand Down
@@ -0,0 +1,3 @@
"use strict";

/** @external foo */
@@ -0,0 +1,37 @@
{
"type": "File",
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":20}},
"program": {
"type": "Program",
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":20}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"trailingComments": [
{
"type": "CommentBlock",
"value": "* @external foo ",
"start":15,"end":35,"loc":{"start":{"line":3,"column":0,"index":15},"end":{"line":3,"column":20,"index":35}}
}
],
"expression": {
"type": "Literal",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"value": "use strict",
"raw": "\"use strict\""
},
"directive": "use strict"
}
]
},
"comments": [
{
"type": "CommentBlock",
"value": "* @external foo ",
"start":15,"end":35,"loc":{"start":{"line":3,"column":0,"index":15},"end":{"line":3,"column":20,"index":35}}
}
]
}