mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-02 08:15:56 +01:00
Fix source path duplication in NLS plugin source maps and add corresponding test (#300487)
This commit is contained in:
@@ -427,7 +427,11 @@ export function nlsPlugin(options: NLSPluginOptions): esbuild.Plugin {
|
||||
// back to the original. Embed it inline so esbuild composes it
|
||||
// with its own bundle source map, making the final map point to
|
||||
// the original TS source.
|
||||
const sourceName = relativePath.replace(/\\/g, '/');
|
||||
// This inline source map is resolved relative to esbuild's sourcefile
|
||||
// for args.path. Using the full repo-relative path here makes esbuild
|
||||
// resolve it against the file's own directory, which duplicates the
|
||||
// directory segments in the final bundled source map.
|
||||
const sourceName = path.basename(args.path);
|
||||
const sourcemap = generateNLSSourceMap(source, sourceName, edits);
|
||||
const encodedMap = Buffer.from(sourcemap).toString('base64');
|
||||
const contentsWithMap = code + `\n//# sourceMappingURL=data:application/json;base64,${encodedMap}\n`;
|
||||
|
||||
@@ -220,6 +220,28 @@ suite('NLS plugin source maps', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('NLS-affected nested file keeps a non-duplicated source path', async () => {
|
||||
const source = [
|
||||
'import { localize } from "../../vs/nls";',
|
||||
'export const msg = localize("myKey", "Hello World");',
|
||||
].join('\n');
|
||||
|
||||
const { mapJson, cleanup } = await bundleWithNLS(
|
||||
{ 'nested/deep/file.ts': source },
|
||||
'nested/deep/file.ts',
|
||||
);
|
||||
|
||||
try {
|
||||
const sources: string[] = mapJson.sources ?? [];
|
||||
const nestedSource = sources.find((s: string) => s.endsWith('/nested/deep/file.ts'));
|
||||
assert.ok(nestedSource, 'Should find nested/deep/file.ts in sources');
|
||||
assert.ok(!nestedSource.includes('/nested/deep/nested/deep/file.ts'),
|
||||
`Source path should not duplicate directory segments. Actual: ${nestedSource}`);
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('line mapping correct for code after localize calls', async () => {
|
||||
const source = [
|
||||
'import { localize } from "../vs/nls";', // 1
|
||||
|
||||
Reference in New Issue
Block a user