Skip to content

Commit

Permalink
Merge branch 'master' into completionsRecommended
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-ms committed Nov 17, 2017
2 parents 4a757e9 + 9992395 commit d1abfbe
Show file tree
Hide file tree
Showing 260 changed files with 12,539 additions and 2,058 deletions.
10 changes: 10 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
[submodule "tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter"]
path = tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter
url = https://github.com/Microsoft/TypeScript-React-Starter
ignore = all
shallow = true
[submodule "tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter"]
path = tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter
url = https://github.com/Microsoft/TypeScript-Node-Starter.git
ignore = all
shallow = true
[submodule "tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter"]
path = tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter
url = https://github.com/Microsoft/TypeScript-React-Native-Starter.git
ignore = all
shallow = true
[submodule "tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter"]
path = tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter
url = https://github.com/Microsoft/TypeScript-Vue-Starter.git
ignore = all
shallow = true
[submodule "tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter"]
path = tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter
url = https://github.com/Microsoft/TypeScript-WeChat-Starter.git
ignore = all
shallow = true
6 changes: 3 additions & 3 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@ namespace ts {

function bindAnonymousDeclaration(node: Declaration, symbolFlags: SymbolFlags, name: __String) {
const symbol = createSymbol(symbolFlags, name);
if (symbolFlags & SymbolFlags.EnumMember) {
if (symbolFlags & (SymbolFlags.EnumMember | SymbolFlags.ClassMember)) {
symbol.parent = container.symbol;
}
addDeclarationToSymbol(symbol, node, symbolFlags);
Expand Down Expand Up @@ -1835,7 +1835,7 @@ namespace ts {
}

function checkStrictModeNumericLiteral(node: NumericLiteral) {
if (inStrictMode && node.numericLiteralFlags & NumericLiteralFlags.Octal) {
if (inStrictMode && node.numericLiteralFlags & TokenFlags.Octal) {
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
}
}
Expand Down Expand Up @@ -3319,7 +3319,7 @@ namespace ts {
break;

case SyntaxKind.NumericLiteral:
if ((<NumericLiteral>node).numericLiteralFlags & NumericLiteralFlags.BinaryOrOctalSpecifier) {
if ((<NumericLiteral>node).numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier) {
transformFlags |= TransformFlags.AssertES2015;
}
break;
Expand Down
968 changes: 736 additions & 232 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,10 @@ namespace ts {
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
}

export function removeSuffix(str: string, suffix: string): string {
return endsWith(str, suffix) ? str.slice(0, str.length - suffix.length) : str;
}

export function stringContains(str: string, substring: string): boolean {
return str.indexOf(substring) !== -1;
}
Expand Down
118 changes: 107 additions & 11 deletions src/compiler/declarationEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ namespace ts {
const writer = <EmitTextWriterWithSymbolWriter>createTextWriter(newLine);
writer.trackSymbol = trackSymbol;
writer.reportInaccessibleThisError = reportInaccessibleThisError;
writer.reportInaccessibleUniqueSymbolError = reportInaccessibleUniqueSymbolError;
writer.reportPrivateInBaseOfClassExpression = reportPrivateInBaseOfClassExpression;
writer.writeKeyword = writer.write;
writer.writeOperator = writer.write;
Expand Down Expand Up @@ -322,11 +323,21 @@ namespace ts {
}
}

function reportInaccessibleUniqueSymbolError() {
if (errorNameNode) {
reportedDeclarationError = true;
emitterDiagnostics.add(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary,
declarationNameToString(errorNameNode),
"unique symbol"));
}
}

function reportInaccessibleThisError() {
if (errorNameNode) {
reportedDeclarationError = true;
emitterDiagnostics.add(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary,
declarationNameToString(errorNameNode)));
emitterDiagnostics.add(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary,
declarationNameToString(errorNameNode),
"this"));
}
}

Expand Down Expand Up @@ -1227,7 +1238,7 @@ namespace ts {
}

function emitPropertyDeclaration(node: Declaration) {
if (hasDynamicName(node)) {
if (hasDynamicName(node) && !resolver.isLateBound(node)) {
return;
}

Expand All @@ -1246,10 +1257,8 @@ namespace ts {
emitBindingPattern(<BindingPattern>node.name);
}
else {
// If this node is a computed name, it can only be a symbol, because we've already skipped
// it if it's not a well known symbol. In that case, the text of the name will be exactly
// what we want, namely the name expression enclosed in brackets.
writeTextOfNode(currentText, node.name);
writeNameOfDeclaration(node, getVariableDeclarationTypeVisibilityError);

// If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor
// we don't want to emit property declaration with "?"
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature ||
Expand Down Expand Up @@ -1387,7 +1396,7 @@ namespace ts {
}

function emitAccessorDeclaration(node: AccessorDeclaration) {
if (hasDynamicName(node)) {
if (hasDynamicName(node) && !resolver.isLateBound(node)) {
return;
}

Expand All @@ -1398,7 +1407,7 @@ namespace ts {
emitJsDocComments(accessors.getAccessor);
emitJsDocComments(accessors.setAccessor);
emitClassMemberDeclarationFlags(getModifierFlags(node) | (accessors.setAccessor ? 0 : ModifierFlags.Readonly));
writeTextOfNode(currentText, node.name);
writeNameOfDeclaration(node, getAccessorNameVisibilityError);
if (!hasModifier(node, ModifierFlags.Private)) {
accessorWithTypeAnnotation = node;
let type = getTypeAnnotationFromAccessor(node);
Expand Down Expand Up @@ -1426,6 +1435,37 @@ namespace ts {
}
}

function getAccessorNameVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) {
const diagnosticMessage = getAccessorNameVisibilityDiagnosticMessage(symbolAccessibilityResult);
return diagnosticMessage !== undefined ? {
diagnosticMessage,
errorNode: node,
typeName: node.name
} : undefined;
}

function getAccessorNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) {
if (hasModifier(node, ModifierFlags.Static)) {
return symbolAccessibilityResult.errorModuleName ?
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
}
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
return symbolAccessibilityResult.errorModuleName ?
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
}
else {
return symbolAccessibilityResult.errorModuleName ?
Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
}
}

function getAccessorDeclarationTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic {
let diagnosticMessage: DiagnosticMessage;
if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) {
Expand Down Expand Up @@ -1467,7 +1507,7 @@ namespace ts {
}

function writeFunctionDeclaration(node: FunctionLikeDeclaration) {
if (hasDynamicName(node)) {
if (hasDynamicName(node) && !resolver.isLateBound(node)) {
return;
}

Expand All @@ -1489,13 +1529,69 @@ namespace ts {
write("constructor");
}
else {
writeTextOfNode(currentText, node.name);
writeNameOfDeclaration(node, getMethodNameVisibilityError);
if (hasQuestionToken(node)) {
write("?");
}
}
emitSignatureDeclaration(node);
}

function getMethodNameVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic {
const diagnosticMessage = getMethodNameVisibilityDiagnosticMessage(symbolAccessibilityResult);
return diagnosticMessage !== undefined ? {
diagnosticMessage,
errorNode: node,
typeName: node.name
} : undefined;
}

function getMethodNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) {
if (hasModifier(node, ModifierFlags.Static)) {
return symbolAccessibilityResult.errorModuleName ?
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_private_name_1;
}
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
return symbolAccessibilityResult.errorModuleName ?
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
Diagnostics.Public_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
Diagnostics.Public_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Public_method_0_of_exported_class_has_or_is_using_private_name_1;
}
else {
return symbolAccessibilityResult.errorModuleName ?
Diagnostics.Method_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Method_0_of_exported_interface_has_or_is_using_private_name_1;
}
}
}

function writeNameOfDeclaration(node: NamedDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
if (hasDynamicName(node)) {
// If this node has a dynamic name, it can only be an identifier or property access because
// we've already skipped it otherwise.
Debug.assert(resolver.isLateBound(node));

writeLateBoundNameOfDeclaration(node as LateBoundDeclaration, getSymbolAccessibilityDiagnostic);
}
else {
// If this node is a computed name, it can only be a symbol, because we've already skipped
// it if it's not a well known symbol. In that case, the text of the name will be exactly
// what we want, namely the name expression enclosed in brackets.
writeTextOfNode(currentText, node.name);
}
}

function writeLateBoundNameOfDeclaration(node: LateBoundDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
const entityName = node.name.expression;
const visibilityResult = resolver.isEntityNameVisible(entityName, enclosingDeclaration);
handleSymbolAccessibilityError(visibilityResult);
recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForEntityName(entityName));
writeTextOfNode(currentText, node.name);
}

function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) {
Expand Down
Loading

0 comments on commit d1abfbe

Please sign in to comment.