Skip to content

Commit d0a20c7

Browse files
committed
Merge remote-tracking branch 'Microsoft/master' into tsconfigpath
2 parents c850919 + 784fe58 commit d0a20c7

136 files changed

Lines changed: 2618 additions & 681 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ scripts/typings/
5050
coverage/
5151
internal/
5252
**/.DS_Store
53-
.settings/*
54-
!.settings/tasks.json
53+
.settings
54+
.vscode/*
55+
!.vscode/tasks.json

.npmignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ doc
33
scripts
44
src
55
tests
6-
Jakefile
6+
Jakefile.js
77
.travis.yml
8-
.settings/
8+
.settings/
9+
.vscode/

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Design changes will not be accepted at this time. If you have a design change pr
99
## Legal
1010
You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright.
1111

12-
Please submit a Contributor License Agreement (CLA) before submitting a pull request. You may visit https://cla.microsoft.com to sign digitally. Alternatively, download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to <cla@microsoft.com>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features.
12+
Please submit a Contributor License Agreement (CLA) before submitting a pull request. You may visit https://cla.microsoft.com to sign digitally. Alternatively, download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to <cla@microsoft.com>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request.
1313

1414
## Housekeeping
1515
Your pull request should:

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
"build": "npm run build:compiler && npm run build:tests",
4545
"build:compiler": "jake local",
4646
"build:tests": "jake tests",
47-
"clean": "jake clean"
47+
"clean": "jake clean",
48+
"jake": "jake",
49+
"setup-hooks": "node scripts/link-hooks.js"
4850
},
4951
"browser": {
5052
"buffer": false,

scripts/hooks/post-checkout

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
npm run jake -- generate-diagnostics

scripts/link-hooks.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var fs = require("fs");
2+
var path = require("path");
3+
4+
var hooks = [
5+
"post-checkout"
6+
];
7+
8+
hooks.forEach(function (hook) {
9+
var hookInSourceControl = path.resolve(__dirname, "hooks", hook);
10+
11+
if (fs.existsSync(hookInSourceControl)) {
12+
var hookInHiddenDirectory = path.resolve(__dirname, "..", ".git", "hooks", hook);
13+
14+
if (fs.existsSync(hookInHiddenDirectory)) {
15+
fs.unlinkSync(hookInHiddenDirectory);
16+
}
17+
18+
fs.linkSync(hookInSourceControl, hookInHiddenDirectory);
19+
}
20+
});

src/compiler/checker.ts

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace ts {
4444

4545
let compilerOptions = host.getCompilerOptions();
4646
let languageVersion = compilerOptions.target || ScriptTarget.ES3;
47+
let modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None;
4748

4849
let emitResolver = createResolver();
4950

@@ -2293,10 +2294,17 @@ namespace ts {
22932294
return type && (type.flags & TypeFlags.Any) !== 0;
22942295
}
22952296

2297+
// Return the type of a binding element parent. We check SymbolLinks first to see if a type has been
2298+
// assigned by contextual typing.
2299+
function getTypeForBindingElementParent(node: VariableLikeDeclaration) {
2300+
let symbol = getSymbolOfNode(node);
2301+
return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node);
2302+
}
2303+
22962304
// Return the inferred type for a binding element
22972305
function getTypeForBindingElement(declaration: BindingElement): Type {
22982306
let pattern = <BindingPattern>declaration.parent;
2299-
let parentType = getTypeForVariableLikeDeclaration(<VariableLikeDeclaration>pattern.parent);
2307+
let parentType = getTypeForBindingElementParent(<VariableLikeDeclaration>pattern.parent);
23002308
// If parent has the unknown (error) type, then so does this binding element
23012309
if (parentType === unknownType) {
23022310
return unknownType;
@@ -9162,10 +9170,24 @@ namespace ts {
91629170
}
91639171
}
91649172

9173+
// When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
9174+
// the destructured type into the contained binding elements.
9175+
function assignBindingElementTypes(node: VariableLikeDeclaration) {
9176+
if (isBindingPattern(node.name)) {
9177+
for (let element of (<BindingPattern>node.name).elements) {
9178+
if (element.kind !== SyntaxKind.OmittedExpression) {
9179+
getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
9180+
assignBindingElementTypes(element);
9181+
}
9182+
}
9183+
}
9184+
}
9185+
91659186
function assignTypeToParameterAndFixTypeParameters(parameter: Symbol, contextualType: Type, mapper: TypeMapper) {
91669187
let links = getSymbolLinks(parameter);
91679188
if (!links.type) {
91689189
links.type = instantiateType(contextualType, mapper);
9190+
assignBindingElementTypes(<ParameterDeclaration>parameter.valueDeclaration);
91699191
}
91709192
else if (isInferentialContext(mapper)) {
91719193
// Even if the parameter already has a type, it might be because it was given a type while
@@ -12940,26 +12962,41 @@ namespace ts {
1294012962
if (!(nodeLinks.flags & NodeCheckFlags.EnumValuesComputed)) {
1294112963
let enumSymbol = getSymbolOfNode(node);
1294212964
let enumType = getDeclaredTypeOfSymbol(enumSymbol);
12943-
let autoValue = 0;
12965+
let autoValue = 0; // set to undefined when enum member is non-constant
1294412966
let ambient = isInAmbientContext(node);
1294512967
let enumIsConst = isConst(node);
1294612968

12947-
forEach(node.members, member => {
12948-
if (member.name.kind !== SyntaxKind.ComputedPropertyName && isNumericLiteralName((<Identifier>member.name).text)) {
12969+
for (const member of node.members) {
12970+
if (member.name.kind === SyntaxKind.ComputedPropertyName) {
12971+
error(member.name, Diagnostics.Computed_property_names_are_not_allowed_in_enums);
12972+
}
12973+
else if (isNumericLiteralName((<Identifier>member.name).text)) {
1294912974
error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
1295012975
}
12976+
12977+
const previousEnumMemberIsNonConstant = autoValue === undefined;
12978+
1295112979
let initializer = member.initializer;
1295212980
if (initializer) {
1295312981
autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient);
1295412982
}
1295512983
else if (ambient && !enumIsConst) {
12984+
// In ambient enum declarations that specify no const modifier, enum member declarations
12985+
// that omit a value are considered computed members (as opposed to having auto-incremented values assigned).
1295612986
autoValue = undefined;
1295712987
}
12988+
else if (previousEnumMemberIsNonConstant) {
12989+
// If the member declaration specifies no value, the member is considered a constant enum member.
12990+
// If the member is the first member in the enum declaration, it is assigned the value zero.
12991+
// Otherwise, it is assigned the value of the immediately preceding member plus one,
12992+
// and an error occurs if the immediately preceding member is not a constant enum member
12993+
error(member.name, Diagnostics.Enum_member_must_have_initializer);
12994+
}
1295812995

1295912996
if (autoValue !== undefined) {
1296012997
getNodeLinks(member).enumMemberValue = autoValue++;
1296112998
}
12962-
});
12999+
}
1296313000

1296413001
nodeLinks.flags |= NodeCheckFlags.EnumValuesComputed;
1296513002
}
@@ -12975,11 +13012,11 @@ namespace ts {
1297513012
if (enumIsConst) {
1297613013
error(initializer, Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression);
1297713014
}
12978-
else if (!ambient) {
13015+
else if (ambient) {
13016+
error(initializer, Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression);
13017+
}
13018+
else {
1297913019
// Only here do we need to check that the initializer is assignable to the enum type.
12980-
// If it is a constant value (not undefined), it is syntactically constrained to be a number.
12981-
// Also, we do not need to check this for ambients because there is already
12982-
// a syntax error if it is not a constant.
1298313020
checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined);
1298413021
}
1298513022
}
@@ -13119,7 +13156,7 @@ namespace ts {
1311913156
}
1312013157

1312113158
// Grammar checking
13122-
checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node);
13159+
checkGrammarDecorators(node) || checkGrammarModifiers(node);
1312313160

1312413161
checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0);
1312513162
checkCollisionWithCapturedThisVariable(node, node.name);
@@ -13379,9 +13416,9 @@ namespace ts {
1337913416
}
1338013417
}
1338113418
else {
13382-
if (languageVersion >= ScriptTarget.ES6 && !isInAmbientContext(node)) {
13419+
if (modulekind === ModuleKind.ES6 && !isInAmbientContext(node)) {
1338313420
// Import equals declaration is deprecated in es6 or above
13384-
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead);
13421+
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
1338513422
}
1338613423
}
1338713424
}
@@ -13456,11 +13493,11 @@ namespace ts {
1345613493
checkExternalModuleExports(<SourceFile | ModuleDeclaration>container);
1345713494

1345813495
if (node.isExportEquals && !isInAmbientContext(node)) {
13459-
if (languageVersion >= ScriptTarget.ES6) {
13460-
// export assignment is deprecated in es6 or above
13461-
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead);
13496+
if (modulekind === ModuleKind.ES6) {
13497+
// export assignment is not supported in es6 modules
13498+
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead);
1346213499
}
13463-
else if (compilerOptions.module === ModuleKind.System) {
13500+
else if (modulekind === ModuleKind.System) {
1346413501
// system modules does not support export assignment
1346513502
grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
1346613503
}
@@ -15619,40 +15656,6 @@ namespace ts {
1561915656
return false;
1562015657
}
1562115658

15622-
function checkGrammarEnumDeclaration(enumDecl: EnumDeclaration): boolean {
15623-
let enumIsConst = (enumDecl.flags & NodeFlags.Const) !== 0;
15624-
15625-
let hasError = false;
15626-
15627-
// skip checks below for const enums - they allow arbitrary initializers as long as they can be evaluated to constant expressions.
15628-
// since all values are known in compile time - it is not necessary to check that constant enum section precedes computed enum members.
15629-
if (!enumIsConst) {
15630-
let inConstantEnumMemberSection = true;
15631-
let inAmbientContext = isInAmbientContext(enumDecl);
15632-
for (let node of enumDecl.members) {
15633-
// Do not use hasDynamicName here, because that returns false for well known symbols.
15634-
// We want to perform checkComputedPropertyName for all computed properties, including
15635-
// well known symbols.
15636-
if (node.name.kind === SyntaxKind.ComputedPropertyName) {
15637-
hasError = grammarErrorOnNode(node.name, Diagnostics.Computed_property_names_are_not_allowed_in_enums);
15638-
}
15639-
else if (inAmbientContext) {
15640-
if (node.initializer && !isIntegerLiteral(node.initializer)) {
15641-
hasError = grammarErrorOnNode(node.name, Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError;
15642-
}
15643-
}
15644-
else if (node.initializer) {
15645-
inConstantEnumMemberSection = isIntegerLiteral(node.initializer);
15646-
}
15647-
else if (!inConstantEnumMemberSection) {
15648-
hasError = grammarErrorOnNode(node.name, Diagnostics.Enum_member_must_have_initializer) || hasError;
15649-
}
15650-
}
15651-
}
15652-
15653-
return hasError;
15654-
}
15655-
1565615659
function hasParseDiagnostics(sourceFile: SourceFile): boolean {
1565715660
return sourceFile.parseDiagnostics.length > 0;
1565815661
}

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ namespace ts {
7676
"amd": ModuleKind.AMD,
7777
"system": ModuleKind.System,
7878
"umd": ModuleKind.UMD,
79+
"es6": ModuleKind.ES6,
7980
},
80-
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd,
81+
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6,
8182
paramType: Diagnostics.KIND,
82-
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd
83+
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6
8384
},
8485
{
8586
name: "newLine",

src/compiler/diagnosticMessages.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
"category": "Error",
196196
"code": 1063
197197
},
198-
"Ambient enum elements can only have integer literal initializers.": {
198+
"In ambient enum declarations member initializer must be constant expression.": {
199199
"category": "Error",
200200
"code": 1066
201201
},
@@ -619,15 +619,15 @@
619619
"category": "Error",
620620
"code": 1200
621621
},
622-
"Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead.": {
622+
"Import assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead.": {
623623
"category": "Error",
624624
"code": 1202
625625
},
626-
"Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead.": {
626+
"Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead.": {
627627
"category": "Error",
628628
"code": 1203
629629
},
630-
"Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.": {
630+
"Cannot compile modules into 'es6' when targeting 'ES5' or lower.": {
631631
"category": "Error",
632632
"code": 1204
633633
},
@@ -2109,7 +2109,7 @@
21092109
"category": "Message",
21102110
"code": 6015
21112111
},
2112-
"Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'": {
2112+
"Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'": {
21132113
"category": "Message",
21142114
"code": 6016
21152115
},
@@ -2193,7 +2193,7 @@
21932193
"category": "Error",
21942194
"code": 6045
21952195
},
2196-
"Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'.": {
2196+
"Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'.": {
21972197
"category": "Error",
21982198
"code": 6046
21992199
},

0 commit comments

Comments
 (0)