Conversation
There was a problem hiding this comment.
Pull request overview
This PR aligns tsgo’s source map emission with the reference TypeScript emitter, reducing baseline diffs across a wide set of sourcemap validation fixtures.
Changes:
- Adjust source map range selection for
var-like declarations (enum vs non-enum) in the runtime syntax transformer. - Refine printer sourcemap behavior by skipping trivia for token sourcemap positions and suppressing sourcemaps for function bodies.
- Update/clean reference baselines (many
.difffiles removed and.sourcemap.txt/.js.map.diffupdated) to reflect the corrected emitter behavior.
Reviewed changes
Copilot reviewed 73 out of 333 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForArrayBindingPattern(target=es2015).sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForArrayBindingPattern(target=es2015).sourcemap.txt | Updated expected sourcemap output to match new emitter behavior. |
| testdata/baselines/reference/submodule/compiler/sourceMapValidationDecorators(target=es2015).sourcemap.txt.diff | Updated baseline diff to reflect reduced/shifted mapping differences. |
| testdata/baselines/reference/submodule/compiler/sourceMapValidationDecorators(target=es2015).sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/sourceMapValidationClasses.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/sourceMapValidationClass(target=es2015).sourcemap.txt.diff | Updated baseline diff to reflect new token/body mapping behavior. |
| testdata/baselines/reference/submodule/compiler/sourceMapValidationClass(target=es2015).sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/sourceMapSample.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/sourceMapForFunctionWithCommentPrecedingStatement01.sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/sourceMapForFunctionWithCommentPrecedingStatement01.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/sourceMapForFunctionWithCommentPrecedingStatement01.js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/sourceMapForFunctionInInternalModuleWithCommentPrecedingStatement01.sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/sourceMapForFunctionInInternalModuleWithCommentPrecedingStatement01.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/sourceMapForFunctionInInternalModuleWithCommentPrecedingStatement01.js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/sourceMap-StringLiteralWithNewLine(target=es2015).sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/sourceMap-StringLiteralWithNewLine(target=es2015).sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/sourceMap-StringLiteralWithNewLine(target=es2015).js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/sourceMap-FileWithComments.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/sourceMap-Comments2(target=es2015).sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/sourceMap-Comments2(target=es2015).sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/sourceMap-Comments2(target=es2015).js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/sourceMap-Comments(target=es2015).sourcemap.txt.diff | Reduced baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/sourceMap-Comments(target=es2015).sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern2.sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern2.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern2.js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern1.sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern1.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern1.js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/properties(target=es2015).sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/properties(target=es2015).sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/properties(target=es2015).js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/out-flag(target=es2015).sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/out-flag(target=es2015).sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/out-flag(target=es2015).js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryQualifiedNameResolutionError.sourcemap.txt.diff | Updated baseline diff to reflect new token/body mapping behavior. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryQualifiedNameResolutionError.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryQualifiedNameResolutionError.js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryQualifiedName.sourcemap.txt.diff | Reduced baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryQualifiedName.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryIdentifierWithAbsentParameter.sourcemap.txt.diff | Updated baseline diff to reflect new token/body mapping behavior. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryIdentifierWithAbsentParameter.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryIdentifierWithAbsentParameter.js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryIdentifierAsParameter.sourcemap.txt.diff | Updated baseline diff to reflect new token/body mapping behavior. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryIdentifierAsParameter.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryIdentifierAsParameter.js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryIdentifier.sourcemap.txt.diff | Reduced baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/jsxFactoryIdentifier.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/jsFileCompilationWithMapFileAsJsWithOutDir.sourcemap.txt.diff | Removed resolved baseline diff after sourcemap alignment. |
| testdata/baselines/reference/submodule/compiler/jsFileCompilationWithMapFileAsJsWithOutDir.sourcemap.txt | Updated expected sourcemap output. |
| testdata/baselines/reference/submodule/compiler/jsFileCompilationWithMapFileAsJsWithOutDir.js.map.diff | Updated expected .js.map diff output. |
| testdata/baselines/reference/submodule/compiler/derivedClassConstructorWithExplicitReturns01(target=es2015).sourcemap.txt.diff | Updated baseline diff to reflect new token/body mapping behavior. |
| testdata/baselines/reference/submodule/compiler/derivedClassConstructorWithExplicitReturns01(target=es2015).sourcemap.txt | Updated expected sourcemap output. |
| internal/transformers/tstransforms/runtimesyntax.go | Adjusted which node receives the source map range for var declarations (enum vs non-enum). |
| internal/printer/printer.go | Updated source map and comment emission logic (skip trivia for token positions; suppress sourcemaps for function bodies). |
| } | ||
| if pos >= 0 { | ||
| p.emitSourcePos(p.sourceMapSource, pos) // !!! support SourceMapRange from Strada? | ||
| pos = scanner.SkipTrivia(p.currentSourceFile.Text(), pos) |
There was a problem hiding this comment.
emitSourceMapsBeforeToken now unconditionally dereferences p.currentSourceFile when pos >= 0. If the printer is used in a context where p.currentSourceFile is nil (e.g. printing detached/synthetic nodes while sourcemaps are enabled), this will panic. Consider guarding the SkipTrivia call similarly to emitCommentsBeforeToken (check p.currentSourceFile != nil and skip only for non-synthesized positions), and fall back to emitting pos unchanged when no source file text is available.
| pos = scanner.SkipTrivia(p.currentSourceFile.Text(), pos) | |
| if p.currentSourceFile != nil && !ast.PositionIsSynthesized(pos) { | |
| pos = scanner.SkipTrivia(p.currentSourceFile.Text(), pos) | |
| } |
Pulling these out of my ES2022 branch; these are misc sourcemap related fixes that remove a lot of diffs.