Skip to content

Commit 034ba9f

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into feature/eslint
2 parents 9732930 + 624d1ca commit 034ba9f

File tree

82 files changed

+1373
-7823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1373
-7823
lines changed

Gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,10 @@ task("runtests-parallel").flags = {
446446
" --shardId": "1-based ID of this shard (default: 1)",
447447
};
448448

449-
task("diff", () => exec(getDiffTool(), [refBaseline, localBaseline], { ignoreExitCode: true }));
449+
task("diff", () => exec(getDiffTool(), [refBaseline, localBaseline], { ignoreExitCode: true, waitForExit: false }));
450450
task("diff").description = "Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable";
451451

452-
task("diff-rwc", () => exec(getDiffTool(), [refRwcBaseline, localRwcBaseline], { ignoreExitCode: true }));
452+
task("diff-rwc", () => exec(getDiffTool(), [refRwcBaseline, localRwcBaseline], { ignoreExitCode: true, waitForExit: false }));
453453
task("diff-rwc").description = "Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable";
454454

455455
/**

lib/enu/diagnosticMessages.generated.json.lcg

Lines changed: 0 additions & 7664 deletions
This file was deleted.

scripts/build/utils.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,45 @@ const isWindows = /^win/.test(process.platform);
2525
* @property {boolean} [ignoreExitCode]
2626
* @property {import("prex").CancellationToken} [cancelToken]
2727
* @property {boolean} [hidePrompt]
28+
* @property {boolean} [waitForExit=true]
2829
*/
2930
function exec(cmd, args, options = {}) {
3031
return /**@type {Promise<{exitCode: number}>}*/(new Promise((resolve, reject) => {
31-
const { ignoreExitCode, cancelToken = CancellationToken.none } = options;
32+
const { ignoreExitCode, cancelToken = CancellationToken.none, waitForExit = true } = options;
3233
cancelToken.throwIfCancellationRequested();
3334

3435
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
3536
const subshellFlag = isWindows ? "/c" : "-c";
3637
const command = isWindows ? [possiblyQuote(cmd), ...args] : [`${cmd} ${args.join(" ")}`];
3738

3839
if (!options.hidePrompt) log(`> ${chalk.green(cmd)} ${args.join(" ")}`);
39-
const proc = spawn(isWindows ? "cmd" : "/bin/sh", [subshellFlag, ...command], { stdio: "inherit", windowsVerbatimArguments: true });
40+
const proc = spawn(isWindows ? "cmd" : "/bin/sh", [subshellFlag, ...command], { stdio: waitForExit ? "inherit" : "ignore", windowsVerbatimArguments: true });
4041
const registration = cancelToken.register(() => {
4142
log(`${chalk.red("killing")} '${chalk.green(cmd)} ${args.join(" ")}'...`);
4243
proc.kill("SIGINT");
4344
proc.kill("SIGTERM");
4445
reject(new CancelError());
4546
});
46-
proc.on("exit", exitCode => {
47-
registration.unregister();
48-
if (exitCode === 0 || ignoreExitCode) {
49-
resolve({ exitCode });
50-
}
51-
else {
52-
reject(new Error(`Process exited with code: ${exitCode}`));
53-
}
54-
});
55-
proc.on("error", error => {
56-
registration.unregister();
57-
reject(error);
58-
});
47+
if (waitForExit) {
48+
proc.on("exit", exitCode => {
49+
registration.unregister();
50+
if (exitCode === 0 || ignoreExitCode) {
51+
resolve({ exitCode });
52+
}
53+
else {
54+
reject(new Error(`Process exited with code: ${exitCode}`));
55+
}
56+
});
57+
proc.on("error", error => {
58+
registration.unregister();
59+
reject(error);
60+
});
61+
}
62+
else {
63+
proc.unref();
64+
// wait a short period in order to allow the process to start successfully before Node exits.
65+
setTimeout(() => resolve({ exitCode: undefined }), 100);
66+
}
5967
}));
6068
}
6169
exports.exec = exec;

scripts/produceLKG.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ async function copyLibFiles() {
2727

2828
async function copyLocalizedDiagnostics() {
2929
const dir = await fs.readdir(source);
30+
const ignoredFolders = ["enu"];
31+
3032
for (const d of dir) {
3133
const fileName = path.join(source, d);
32-
if (fs.statSync(fileName).isDirectory()) {
34+
if (
35+
fs.statSync(fileName).isDirectory() &&
36+
ignoredFolders.indexOf(d) < 0
37+
) {
3338
await fs.copy(fileName, path.join(dest, d));
3439
}
3540
}

src/compiler/checker.ts

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,7 +2377,7 @@ namespace ts {
23772377
return links.target;
23782378
}
23792379

2380-
function markExportAsReferenced(node: ImportEqualsDeclaration | ExportAssignment | ExportSpecifier) {
2380+
function markExportAsReferenced(node: ImportEqualsDeclaration | ExportSpecifier) {
23812381
const symbol = getSymbolOfNode(node);
23822382
const target = resolveAlias(symbol);
23832383
if (target) {
@@ -2399,15 +2399,10 @@ namespace ts {
23992399
links.referenced = true;
24002400
const node = getDeclarationOfAliasSymbol(symbol);
24012401
if (!node) return Debug.fail();
2402-
if (node.kind === SyntaxKind.ExportAssignment) {
2403-
// export default <symbol>
2404-
checkExpressionCached((<ExportAssignment>node).expression);
2405-
}
2406-
else if (node.kind === SyntaxKind.ExportSpecifier) {
2407-
// export { <symbol> } or export { <symbol> as foo }
2408-
checkExpressionCached((<ExportSpecifier>node).propertyName || (<ExportSpecifier>node).name);
2409-
}
2410-
else if (isInternalModuleImportEqualsDeclaration(node)) {
2402+
// We defer checking of the reference of an `import =` until the import itself is referenced,
2403+
// This way a chain of imports can be elided if ultimately the final input is only used in a type
2404+
// position.
2405+
if (isInternalModuleImportEqualsDeclaration(node)) {
24112406
// import foo = <symbol>
24122407
checkExpressionCached(<Expression>node.moduleReference);
24132408
}
@@ -17829,8 +17824,12 @@ namespace ts {
1782917824
return type;
1783017825
}
1783117826

17827+
function isExportOrExportExpression(location: Node) {
17828+
return !!findAncestor(location, e => e.parent && isExportAssignment(e.parent) && e.parent.expression === e && isEntityNameExpression(e));
17829+
}
17830+
1783217831
function markAliasReferenced(symbol: Symbol, location: Node) {
17833-
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
17832+
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && ((compilerOptions.preserveConstEnums && isExportOrExportExpression(location)) || !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol)))) {
1783417833
markAliasSymbolAsReferenced(symbol);
1783517834
}
1783617835
}
@@ -18812,6 +18811,17 @@ namespace ts {
1881218811
return false;
1881318812
}
1881418813

18814+
function getContextualIterationType(kind: IterationTypeKind, functionDecl: SignatureDeclaration): Type | undefined {
18815+
const isAsync = !!(getFunctionFlags(functionDecl) & FunctionFlags.Async);
18816+
const contextualReturnType = getContextualReturnType(functionDecl);
18817+
if (contextualReturnType) {
18818+
return getIterationTypeOfGeneratorFunctionReturnType(kind, contextualReturnType, isAsync)
18819+
|| undefined;
18820+
}
18821+
18822+
return undefined;
18823+
}
18824+
1881518825
function getContextualReturnType(functionDecl: SignatureDeclaration): Type | undefined {
1881618826
// If the containing function has a return type annotation, is a constructor, or is a get accessor whose
1881718827
// corresponding set accessor has a type annotation, return statements in the function are contextually typed
@@ -20341,8 +20351,8 @@ namespace ts {
2034120351
// if jsx emit was not react as there wont be error being emitted
2034220352
reactSym.isReferenced = SymbolFlags.All;
2034320353

20344-
// If react symbol is alias, mark it as referenced
20345-
if (reactSym.flags & SymbolFlags.Alias && !isConstEnumOrConstEnumOnlyModule(resolveAlias(reactSym))) {
20354+
// If react symbol is alias, mark it as refereced
20355+
if (reactSym.flags & SymbolFlags.Alias) {
2034620356
markAliasSymbolAsReferenced(reactSym);
2034720357
}
2034820358
}
@@ -23477,7 +23487,11 @@ namespace ts {
2347723487
}
2347823488

2347923489
if (isGenerator) {
23480-
return createGeneratorReturnType(yieldType || neverType, returnType || fallbackReturnType, nextType || unknownType, isAsync);
23490+
return createGeneratorReturnType(
23491+
yieldType || neverType,
23492+
returnType || fallbackReturnType,
23493+
nextType || getContextualIterationType(IterationTypeKind.Next, func) || unknownType,
23494+
isAsync);
2348123495
}
2348223496
else {
2348323497
// From within an async function you can return either a non-promise value or a promise. Any
@@ -24839,13 +24853,7 @@ namespace ts {
2483924853
|| anyType;
2484024854
}
2484124855

24842-
const contextualReturnType = getContextualReturnType(func);
24843-
if (contextualReturnType) {
24844-
return getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Next, contextualReturnType, isAsync)
24845-
|| anyType;
24846-
}
24847-
24848-
return anyType;
24856+
return getContextualIterationType(IterationTypeKind.Next, func) || anyType;
2484924857
}
2485024858

2485124859
function checkConditionalExpression(node: ConditionalExpression, checkMode?: CheckMode): Type {
@@ -24894,7 +24902,7 @@ namespace ts {
2489424902
return result;
2489524903
}
2489624904

24897-
function checkExpressionCached(node: Expression, checkMode?: CheckMode): Type {
24905+
function checkExpressionCached(node: Expression | QualifiedName, checkMode?: CheckMode): Type {
2489824906
const links = getNodeLinks(node);
2489924907
if (!links.resolvedType) {
2490024908
if (checkMode && checkMode !== CheckMode.Normal) {
@@ -25222,7 +25230,8 @@ namespace ts {
2522225230
(node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).expression === node) ||
2522325231
(node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).expression === node) ||
2522425232
((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(<Identifier>node) ||
25225-
(node.parent.kind === SyntaxKind.TypeQuery && (<TypeQueryNode>node.parent).exprName === node));
25233+
(node.parent.kind === SyntaxKind.TypeQuery && (<TypeQueryNode>node.parent).exprName === node)) ||
25234+
(node.parent.kind === SyntaxKind.ExportSpecifier && (compilerOptions.preserveConstEnums || node.flags & NodeFlags.Ambient)); // We allow reexporting const enums
2522625235

2522725236
if (!ok) {
2522825237
error(node, Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query);
@@ -30152,6 +30161,10 @@ namespace ts {
3015230161
}
3015330162
else {
3015430163
markExportAsReferenced(node);
30164+
const target = symbol && (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol);
30165+
if (!target || target === unknownSymbol || target.flags & SymbolFlags.Value) {
30166+
checkExpressionCached(node.propertyName || node.name);
30167+
}
3015530168
}
3015630169
}
3015730170
}
@@ -30178,7 +30191,17 @@ namespace ts {
3017830191
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
3017930192
}
3018030193
if (node.expression.kind === SyntaxKind.Identifier) {
30181-
markExportAsReferenced(node);
30194+
const id = node.expression as Identifier;
30195+
const sym = resolveEntityName(id, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, node);
30196+
if (sym) {
30197+
markAliasReferenced(sym, id);
30198+
// If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`)
30199+
const target = sym.flags & SymbolFlags.Alias ? resolveAlias(sym) : sym;
30200+
if (target === unknownSymbol || target.flags & SymbolFlags.Value) {
30201+
// However if it is a value, we need to check it's being used correctly
30202+
checkExpressionCached(node.expression);
30203+
}
30204+
}
3018230205

3018330206
if (getEmitDeclarations(compilerOptions)) {
3018430207
collectLinkedAliases(node.expression as Identifier, /*setVisibility*/ true);

src/compiler/commandLineParser.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,14 +1743,24 @@ namespace ts {
17431743
return false;
17441744
}
17451745

1746+
/** @internal */
1747+
export interface TSConfig {
1748+
compilerOptions: CompilerOptions;
1749+
compileOnSave: boolean | undefined;
1750+
exclude?: ReadonlyArray<string>;
1751+
files: ReadonlyArray<string> | undefined;
1752+
include?: ReadonlyArray<string>;
1753+
references: ReadonlyArray<ProjectReference> | undefined;
1754+
}
1755+
17461756
/**
17471757
* Generate an uncommented, complete tsconfig for use with "--showConfig"
17481758
* @param configParseResult options to be generated into tsconfig.json
17491759
* @param configFileName name of the parsed config file - output paths will be generated relative to this
17501760
* @param host provides current directory and case sensitivity services
17511761
*/
17521762
/** @internal */
1753-
export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { getCurrentDirectory(): string, useCaseSensitiveFileNames: boolean }): object {
1763+
export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { getCurrentDirectory(): string, useCaseSensitiveFileNames: boolean }): TSConfig {
17541764
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
17551765
const files = map(
17561766
filter(
@@ -1778,13 +1788,13 @@ namespace ts {
17781788
build: undefined,
17791789
version: undefined,
17801790
},
1781-
references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath, originalPath: undefined })),
1791+
references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath ? r.originalPath : "", originalPath: undefined })),
17821792
files: length(files) ? files : undefined,
17831793
...(configParseResult.configFileSpecs ? {
17841794
include: filterSameAsDefaultInclude(configParseResult.configFileSpecs.validatedIncludeSpecs),
17851795
exclude: configParseResult.configFileSpecs.validatedExcludeSpecs
17861796
} : {}),
1787-
compilerOnSave: !!configParseResult.compileOnSave ? true : undefined
1797+
compileOnSave: !!configParseResult.compileOnSave ? true : undefined
17881798
};
17891799
return config;
17901800
}

src/compiler/transformers/es2018.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace ts {
2222
const previousOnSubstituteNode = context.onSubstituteNode;
2323
context.onSubstituteNode = onSubstituteNode;
2424

25+
let exportedVariableStatement = false;
2526
let enabledSubstitutions: ESNextSubstitutionFlags;
2627
let enclosingFunctionFlags: FunctionFlags;
2728
let enclosingSuperContainerFlags: NodeCheckFlags = 0;
@@ -40,6 +41,7 @@ namespace ts {
4041
return node;
4142
}
4243

44+
exportedVariableStatement = false;
4345
const visited = visitEachChild(node, visitor, context);
4446
addEmitHelpers(visited, context.readEmitHelpers());
4547
return visited;
@@ -79,6 +81,8 @@ namespace ts {
7981
return visitBinaryExpression(node as BinaryExpression, noDestructuringValue);
8082
case SyntaxKind.CatchClause:
8183
return visitCatchClause(node as CatchClause);
84+
case SyntaxKind.VariableStatement:
85+
return visitVariableStatement(node as VariableStatement);
8286
case SyntaxKind.VariableDeclaration:
8387
return visitVariableDeclaration(node as VariableDeclaration);
8488
case SyntaxKind.ForOfStatement:
@@ -321,19 +325,43 @@ namespace ts {
321325
return visitEachChild(node, visitor, context);
322326
}
323327

328+
function visitVariableStatement(node: VariableStatement): VisitResult<VariableStatement> {
329+
if (hasModifier(node, ModifierFlags.Export)) {
330+
const savedExportedVariableStatement = exportedVariableStatement;
331+
exportedVariableStatement = true;
332+
const visited = visitEachChild(node, visitor, context);
333+
exportedVariableStatement = savedExportedVariableStatement;
334+
return visited;
335+
}
336+
return visitEachChild(node, visitor, context);
337+
}
338+
324339
/**
325340
* Visits a VariableDeclaration node with a binding pattern.
326341
*
327342
* @param node A VariableDeclaration node.
328343
*/
329344
function visitVariableDeclaration(node: VariableDeclaration): VisitResult<VariableDeclaration> {
345+
if (exportedVariableStatement) {
346+
const savedExportedVariableStatement = exportedVariableStatement;
347+
exportedVariableStatement = false;
348+
const visited = visitVariableDeclarationWorker(node, /*exportedVariableStatement*/ true);
349+
exportedVariableStatement = savedExportedVariableStatement;
350+
return visited;
351+
}
352+
return visitVariableDeclarationWorker(node, /*exportedVariableStatement*/ false);
353+
}
354+
355+
function visitVariableDeclarationWorker(node: VariableDeclaration, exportedVariableStatement: boolean): VisitResult<VariableDeclaration> {
330356
// If we are here it is because the name contains a binding pattern with a rest somewhere in it.
331357
if (isBindingPattern(node.name) && node.name.transformFlags & TransformFlags.ContainsObjectRestOrSpread) {
332358
return flattenDestructuringBinding(
333359
node,
334360
visitor,
335361
context,
336-
FlattenLevel.ObjectRest
362+
FlattenLevel.ObjectRest,
363+
/*rval*/ undefined,
364+
exportedVariableStatement
337365
);
338366
}
339367
return visitEachChild(node, visitor, context);

0 commit comments

Comments
 (0)