-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
mod(es/parser): Make the span of Program start at input start #11199
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
Conversation
🦋 Changeset detectedLatest commit: f8671a2 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Pull Request Overview
This PR addresses an issue where the parser incorrectly positioned the program start, causing leading comments and JSDoc annotations to be misplaced after import statements in the generated output. The fix ensures that programs start at the actual beginning of the input, preserving the correct order of comments and code.
Key changes:
- Modified parser to correctly track program start position at input beginning
- Fixed comment positioning for files with leading comments before imports/code
- Updated test fixtures to reflect correct comment placement
Reviewed Changes
Copilot reviewed 293 out of 644 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
Multiple test reference files (.1.normal.js) |
Updated test outputs showing comments now correctly appear before imports instead of after |
| Test fixture output files | Fixed comment positioning in various scenarios including JSDoc, copyright notices, and inline comments |
New test case files (crates/swc/tests/fixture/issues-110xx/11167/) |
Added new test case demonstrating the fix for issue #11167 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Some investigation For code // 123
class A extends B {
}Current swc would output // 123
import { _ as _call_super } from "@swc/helpers/_/_call_super";
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _inherits } from "@swc/helpers/_/_inherits";
var A = /*#__PURE__*/ function(B1) {
"use strict";
_inherits(A, B1);
function A() {
_class_call_check(this, A);
return _call_super(this, A, arguments);
}
return A;
}(B);tsc would output "use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// 123
var A = /** @class */ (function (_super) {
__extends(A, _super);
function A() {
return _super !== null && _super.apply(this, arguments) || this;
}
return A;
}(B));babel would output function _callSuper(t, o, e) { return o = babelHelpers.getPrototypeOf(o), babelHelpers.possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], babelHelpers.getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
// 123
var A = /*#__PURE__*/function (_B) {
function A() {
babelHelpers.classCallCheck(this, A);
return _callSuper(this, A, arguments);
}
babelHelpers.inherits(A, _B);
return babelHelpers.createClass(A);
}(B);This PR would change to babel output. |
|
Some comments would be lost because they're now attached to typescript syntax node which would be eliminated later. |
CodSpeed Performance ReportMerging #11199 will not alter performanceComparing Summary
Footnotes |
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.
Pull Request Overview
Copilot reviewed 293 out of 4003 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull Request Overview
Copilot reviewed 293 out of 4007 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Binary Sizes
Commit: e929313 |
|
CI failures look like a real failure, but I think it may be better to wait until I finish #11205 |
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.
Pull Request Overview
Copilot reviewed 293 out of 4021 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull Request Overview
Copilot reviewed 293 out of 4022 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* | ||
| @internal | ||
| */ declare class StripInternalClassFields { |
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 comment should be removed.
|
I started reviewing this. Sorry for the late review. |
|
@claude Review this PR |
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.
Pull Request Overview
Copilot reviewed 293 out of 4018 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I'll merge after fixing CI with #11277 |
|
@claude Review this PR. Look at only |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
1 similar comment
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
@claude Review this PR. Look at only |
|
Claude finished @kdy1's task —— View job Code Review: Rust Files Only ✅SummaryReviewed 4 Rust files in this PR that fix a fundamental parser positioning issue where program spans incorrectly started at the first token rather than input beginning, causing leading comments to appear after imports instead of before them. File-by-File Analysis✅
|
kdy1
left a comment
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.
Thank you!
kdy1
left a comment
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.
Thank you!
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.
Pull Request Overview
Copilot reviewed 293 out of 4019 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This fixes an issue where top-level comments (like copyright headers) were being lost after PR #11199 changed Module/Script spans to start at position 0. The problem was that Module::emit() was taking and emitting all leading comments before any body items were processed. When helper imports were injected at the beginning, comments would either appear before them (wrong) or be lost entirely. The fix is to skip emitting leading comments at Module/Script level when the body is non-empty. Instead, comments are emitted by the first body item with a real source span. Injected imports have DUMMY_SP, so they skip comment emission, and the original source items emit their comments correctly after the imports. This ensures: - Comments appear after injected imports (maintains fix for #11167) - Comments are not lost (fixes regression from PR #11199) - Module span still starts at position 0 (maintains PR #11199 changes) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Donny/강동윤 <[email protected]>
This fixes an issue where top-level comments (like copyright headers) were being lost after PR #11199 changed Module/Script spans to start at position 0. The fix skips emitting leading comments at Module/Script level when the body is non-empty. Instead, comments are emitted by the first body item with a real source span. Injected imports have DUMMY_SP, so they skip comment emission, and original source items emit their comments correctly after the imports. Closes #11167 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Donny/강동윤 <[email protected]>
Description:
BREAKING CHANGE:
Related issue (if exists):
Closes #11167