mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Fix nls build script on line such as localize2(...) ... localize(...)
(#203851)
For #203842 I believe we need to apply the patches in character order. Otherwise the line ends up corrupted after the patching
This commit is contained in:
parent
31fbc3dc94
commit
0404d17da6
|
@ -311,36 +311,48 @@ var _nls;
|
||||||
function patch(ts, moduleId, typescript, javascript, sourcemap) {
|
function patch(ts, moduleId, typescript, javascript, sourcemap) {
|
||||||
const { localizeCalls, nlsExpressions } = analyze(ts, typescript, 'localize');
|
const { localizeCalls, nlsExpressions } = analyze(ts, typescript, 'localize');
|
||||||
const { localizeCalls: localize2Calls, nlsExpressions: nls2Expressions } = analyze(ts, typescript, 'localize2');
|
const { localizeCalls: localize2Calls, nlsExpressions: nls2Expressions } = analyze(ts, typescript, 'localize2');
|
||||||
if (localizeCalls.length === 0) {
|
if (localizeCalls.length === 0 && localize2Calls.length === 0) {
|
||||||
return { javascript, sourcemap };
|
return { javascript, sourcemap };
|
||||||
}
|
}
|
||||||
const nlsKeys = template(localizeCalls.map(lc => lc.key).concat(localize2Calls.map(lc => lc.key)));
|
const nlsKeys = template(localizeCalls.map(lc => lc.key).concat(localize2Calls.map(lc => lc.key)));
|
||||||
const nls = template(localizeCalls.map(lc => lc.value).concat(localize2Calls.map(lc => lc.value)));
|
const nls = template(localizeCalls.map(lc => lc.value).concat(localize2Calls.map(lc => lc.value)));
|
||||||
const smc = new sm.SourceMapConsumer(sourcemap);
|
const smc = new sm.SourceMapConsumer(sourcemap);
|
||||||
const positionFrom = mappedPositionFrom.bind(null, sourcemap.sources[0]);
|
const positionFrom = mappedPositionFrom.bind(null, sourcemap.sources[0]);
|
||||||
let i = 0;
|
|
||||||
// build patches
|
// build patches
|
||||||
|
const toPatch = (c) => {
|
||||||
|
const start = lcFrom(smc.generatedPositionFor(positionFrom(c.range.start)));
|
||||||
|
const end = lcFrom(smc.generatedPositionFor(positionFrom(c.range.end)));
|
||||||
|
return { span: { start, end }, content: c.content };
|
||||||
|
};
|
||||||
|
let i = 0;
|
||||||
const localizePatches = lazy(localizeCalls)
|
const localizePatches = lazy(localizeCalls)
|
||||||
.map(lc => ([
|
.map(lc => ([
|
||||||
{ range: lc.keySpan, content: '' + (i++) },
|
{ range: lc.keySpan, content: '' + (i++) },
|
||||||
{ range: lc.valueSpan, content: 'null' }
|
{ range: lc.valueSpan, content: 'null' }
|
||||||
]))
|
]))
|
||||||
.flatten()
|
.flatten()
|
||||||
.map(c => {
|
.map(toPatch);
|
||||||
const start = lcFrom(smc.generatedPositionFor(positionFrom(c.range.start)));
|
|
||||||
const end = lcFrom(smc.generatedPositionFor(positionFrom(c.range.end)));
|
|
||||||
return { span: { start, end }, content: c.content };
|
|
||||||
});
|
|
||||||
const localize2Patches = lazy(localize2Calls)
|
const localize2Patches = lazy(localize2Calls)
|
||||||
.map(lc => ([
|
.map(lc => ({ range: lc.keySpan, content: '' + (i++) }))
|
||||||
{ range: lc.keySpan, content: '' + (i++) }
|
.map(toPatch);
|
||||||
])).flatten()
|
// Sort patches by their start position
|
||||||
.map(c => {
|
const patches = localizePatches.concat(localize2Patches).toArray().sort((a, b) => {
|
||||||
const start = lcFrom(smc.generatedPositionFor(positionFrom(c.range.start)));
|
if (a.span.start.line < b.span.start.line) {
|
||||||
const end = lcFrom(smc.generatedPositionFor(positionFrom(c.range.end)));
|
return -1;
|
||||||
return { span: { start, end }, content: c.content };
|
}
|
||||||
|
else if (a.span.start.line > b.span.start.line) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (a.span.start.character < b.span.start.character) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (a.span.start.character > b.span.start.character) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const patches = localizePatches.concat(localize2Patches).toArray();
|
|
||||||
javascript = patchJavascript(patches, javascript, moduleId);
|
javascript = patchJavascript(patches, javascript, moduleId);
|
||||||
// since imports are not within the sourcemap information,
|
// since imports are not within the sourcemap information,
|
||||||
// we must do this MacGyver style
|
// we must do this MacGyver style
|
||||||
|
|
|
@ -414,7 +414,7 @@ module _nls {
|
||||||
const { localizeCalls, nlsExpressions } = analyze(ts, typescript, 'localize');
|
const { localizeCalls, nlsExpressions } = analyze(ts, typescript, 'localize');
|
||||||
const { localizeCalls: localize2Calls, nlsExpressions: nls2Expressions } = analyze(ts, typescript, 'localize2');
|
const { localizeCalls: localize2Calls, nlsExpressions: nls2Expressions } = analyze(ts, typescript, 'localize2');
|
||||||
|
|
||||||
if (localizeCalls.length === 0) {
|
if (localizeCalls.length === 0 && localize2Calls.length === 0) {
|
||||||
return { javascript, sourcemap };
|
return { javascript, sourcemap };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,32 +422,43 @@ module _nls {
|
||||||
const nls = template(localizeCalls.map(lc => lc.value).concat(localize2Calls.map(lc => lc.value)));
|
const nls = template(localizeCalls.map(lc => lc.value).concat(localize2Calls.map(lc => lc.value)));
|
||||||
const smc = new sm.SourceMapConsumer(sourcemap);
|
const smc = new sm.SourceMapConsumer(sourcemap);
|
||||||
const positionFrom = mappedPositionFrom.bind(null, sourcemap.sources[0]);
|
const positionFrom = mappedPositionFrom.bind(null, sourcemap.sources[0]);
|
||||||
let i = 0;
|
|
||||||
|
|
||||||
// build patches
|
// build patches
|
||||||
|
const toPatch = (c: { range: ISpan; content: string }): IPatch => {
|
||||||
|
const start = lcFrom(smc.generatedPositionFor(positionFrom(c.range.start)));
|
||||||
|
const end = lcFrom(smc.generatedPositionFor(positionFrom(c.range.end)));
|
||||||
|
return { span: { start, end }, content: c.content };
|
||||||
|
};
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
const localizePatches = lazy(localizeCalls)
|
const localizePatches = lazy(localizeCalls)
|
||||||
.map(lc => ([
|
.map(lc => ([
|
||||||
{ range: lc.keySpan, content: '' + (i++) },
|
{ range: lc.keySpan, content: '' + (i++) },
|
||||||
{ range: lc.valueSpan, content: 'null' }
|
{ range: lc.valueSpan, content: 'null' }
|
||||||
]))
|
]))
|
||||||
.flatten()
|
.flatten()
|
||||||
.map<IPatch>(c => {
|
.map(toPatch);
|
||||||
const start = lcFrom(smc.generatedPositionFor(positionFrom(c.range.start)));
|
|
||||||
const end = lcFrom(smc.generatedPositionFor(positionFrom(c.range.end)));
|
|
||||||
return { span: { start, end }, content: c.content };
|
|
||||||
});
|
|
||||||
|
|
||||||
const localize2Patches = lazy(localize2Calls)
|
const localize2Patches = lazy(localize2Calls)
|
||||||
.map(lc => ([
|
.map(lc => (
|
||||||
{ range: lc.keySpan, content: '' + (i++) }
|
{ range: lc.keySpan, content: '' + (i++) }
|
||||||
])).flatten()
|
))
|
||||||
.map<IPatch>(c => {
|
.map(toPatch);
|
||||||
const start = lcFrom(smc.generatedPositionFor(positionFrom(c.range.start)));
|
|
||||||
const end = lcFrom(smc.generatedPositionFor(positionFrom(c.range.end)));
|
|
||||||
return { span: { start, end }, content: c.content };
|
|
||||||
});
|
|
||||||
|
|
||||||
const patches = localizePatches.concat(localize2Patches).toArray();
|
// Sort patches by their start position
|
||||||
|
const patches = localizePatches.concat(localize2Patches).toArray().sort((a, b) => {
|
||||||
|
if (a.span.start.line < b.span.start.line) {
|
||||||
|
return -1;
|
||||||
|
} else if (a.span.start.line > b.span.start.line) {
|
||||||
|
return 1;
|
||||||
|
} else if (a.span.start.character < b.span.start.character) {
|
||||||
|
return -1;
|
||||||
|
} else if (a.span.start.character > b.span.start.character) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
javascript = patchJavascript(patches, javascript, moduleId);
|
javascript = patchJavascript(patches, javascript, moduleId);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue