mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 16:34:36 -05:00
Merge branch 'master' into react-factory-option
This commit is contained in:
@@ -840,15 +840,6 @@ namespace ts {
|
||||
return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
|
||||
}
|
||||
|
||||
function getMemberOfModuleVariable(moduleSymbol: Symbol, name: string): Symbol {
|
||||
if (moduleSymbol.flags & SymbolFlags.Variable) {
|
||||
const typeAnnotation = (<VariableDeclaration>moduleSymbol.valueDeclaration).type;
|
||||
if (typeAnnotation) {
|
||||
return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function creates a synthetic symbol that combines the value side of one symbol with the
|
||||
// type/namespace side of another symbol. Consider this example:
|
||||
//
|
||||
@@ -1084,7 +1075,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
const moduleReferenceLiteral = <LiteralExpression>moduleReferenceExpression;
|
||||
const searchPath = getDirectoryPath(getSourceFile(location).fileName);
|
||||
|
||||
// Module names are escaped in our symbol table. However, string literal values aren't.
|
||||
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
|
||||
@@ -2204,65 +2194,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isDeclarationVisible(node: Declaration): boolean {
|
||||
function getContainingExternalModule(node: Node) {
|
||||
for (; node; node = node.parent) {
|
||||
if (node.kind === SyntaxKind.ModuleDeclaration) {
|
||||
if ((<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
else if (node.kind === SyntaxKind.SourceFile) {
|
||||
return isExternalOrCommonJsModule(<SourceFile>node) ? node : undefined;
|
||||
}
|
||||
if (node) {
|
||||
const links = getNodeLinks(node);
|
||||
if (links.isVisible === undefined) {
|
||||
links.isVisible = !!determineIfDeclarationIsVisible();
|
||||
}
|
||||
Debug.fail("getContainingModule cant reach here");
|
||||
return links.isVisible;
|
||||
}
|
||||
|
||||
function isUsedInExportAssignment(node: Node) {
|
||||
// Get source File and see if it is external module and has export assigned symbol
|
||||
const externalModule = getContainingExternalModule(node);
|
||||
let exportAssignmentSymbol: Symbol;
|
||||
let resolvedExportSymbol: Symbol;
|
||||
if (externalModule) {
|
||||
// This is export assigned symbol node
|
||||
const externalModuleSymbol = getSymbolOfNode(externalModule);
|
||||
exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
|
||||
const symbolOfNode = getSymbolOfNode(node);
|
||||
if (isSymbolUsedInExportAssignment(symbolOfNode)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if symbolOfNode is alias declaration, resolve the symbol declaration and check
|
||||
if (symbolOfNode.flags & SymbolFlags.Alias) {
|
||||
return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode));
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the symbol is used in export assignment
|
||||
function isSymbolUsedInExportAssignment(symbol: Symbol) {
|
||||
if (exportAssignmentSymbol === symbol) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & SymbolFlags.Alias)) {
|
||||
// if export assigned symbol is alias declaration, resolve the alias
|
||||
resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol);
|
||||
if (resolvedExportSymbol === symbol) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Container of resolvedExportSymbol is visible
|
||||
return forEach(resolvedExportSymbol.declarations, (current: Node) => {
|
||||
while (current) {
|
||||
if (current === node) {
|
||||
return true;
|
||||
}
|
||||
current = current.parent;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
function determineIfDeclarationIsVisible() {
|
||||
switch (node.kind) {
|
||||
@@ -2341,14 +2281,6 @@ namespace ts {
|
||||
Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
|
||||
}
|
||||
}
|
||||
|
||||
if (node) {
|
||||
const links = getNodeLinks(node);
|
||||
if (links.isVisible === undefined) {
|
||||
links.isVisible = !!determineIfDeclarationIsVisible();
|
||||
}
|
||||
return links.isVisible;
|
||||
}
|
||||
}
|
||||
|
||||
function collectLinkedAliases(node: Identifier): Node[] {
|
||||
@@ -3394,14 +3326,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function addInheritedSignatures(signatures: Signature[], baseSignatures: Signature[]) {
|
||||
if (baseSignatures) {
|
||||
for (const signature of baseSignatures) {
|
||||
signatures.push(signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers {
|
||||
if (!(<InterfaceTypeWithDeclaredMembers>type).declaredProperties) {
|
||||
const symbol = type.symbol;
|
||||
@@ -3890,25 +3814,6 @@ namespace ts {
|
||||
function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] {
|
||||
return getSignaturesOfStructuredType(getApparentType(type), kind);
|
||||
}
|
||||
|
||||
function typeHasConstructSignatures(type: Type): boolean {
|
||||
const apparentType = getApparentType(type);
|
||||
if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Union)) {
|
||||
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
|
||||
return resolved.constructSignatures.length > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function typeHasCallOrConstructSignatures(type: Type): boolean {
|
||||
const apparentType = getApparentType(type);
|
||||
if (apparentType.flags & TypeFlags.StructuredType) {
|
||||
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
|
||||
return resolved.callSignatures.length > 0 || resolved.constructSignatures.length > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type {
|
||||
if (type.flags & TypeFlags.StructuredType) {
|
||||
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
|
||||
@@ -4410,10 +4315,6 @@ namespace ts {
|
||||
return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity);
|
||||
}
|
||||
|
||||
function tryGetGlobalType(name: string, arity = 0): ObjectType {
|
||||
return getTypeOfGlobalSymbol(getGlobalSymbol(name, SymbolFlags.Type, /*diagnostic*/ undefined), arity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a type that is inside a namespace at the global scope, e.g.
|
||||
* getExportedTypeFromNamespace('JSX', 'Element') returns the JSX.Element type
|
||||
@@ -6299,12 +6200,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext {
|
||||
const inferences: TypeInferences[] = [];
|
||||
for (const unused of typeParameters) {
|
||||
inferences.push({
|
||||
primary: undefined, secondary: undefined, isFixed: false
|
||||
});
|
||||
}
|
||||
const inferences = map(typeParameters, createTypeInferencesObject);
|
||||
|
||||
return {
|
||||
typeParameters,
|
||||
inferUnionTypes,
|
||||
@@ -6313,6 +6210,14 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
function createTypeInferencesObject(): TypeInferences {
|
||||
return {
|
||||
primary: undefined,
|
||||
secondary: undefined,
|
||||
isFixed: false,
|
||||
};
|
||||
}
|
||||
|
||||
function inferTypes(context: InferenceContext, source: Type, target: Type) {
|
||||
let sourceStack: Type[];
|
||||
let targetStack: Type[];
|
||||
@@ -6583,10 +6488,6 @@ namespace ts {
|
||||
return context.inferredTypes;
|
||||
}
|
||||
|
||||
function hasAncestor(node: Node, kind: SyntaxKind): boolean {
|
||||
return getAncestor(node, kind) !== undefined;
|
||||
}
|
||||
|
||||
// EXPRESSION TYPE CHECKING
|
||||
|
||||
function getResolvedSymbol(node: Identifier): Symbol {
|
||||
@@ -8206,7 +8107,6 @@ namespace ts {
|
||||
/// type or factory function.
|
||||
/// Otherwise, returns unknownSymbol.
|
||||
function getJsxElementTagSymbol(node: JsxOpeningLikeElement | JsxClosingElement): Symbol {
|
||||
const flags: JsxFlags = JsxFlags.UnknownElement;
|
||||
const links = getNodeLinks(node);
|
||||
if (!links.resolvedSymbol) {
|
||||
if (isJsxIntrinsicIdentifier(node.tagName)) {
|
||||
@@ -14480,16 +14380,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getModuleStatements(node: Declaration): Statement[] {
|
||||
if (node.kind === SyntaxKind.SourceFile) {
|
||||
return (<SourceFile>node).statements;
|
||||
}
|
||||
if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).body.kind === SyntaxKind.ModuleBlock) {
|
||||
return (<ModuleBlock>(<ModuleDeclaration>node).body).statements;
|
||||
}
|
||||
return emptyArray;
|
||||
}
|
||||
|
||||
function hasExportedMembers(moduleSymbol: Symbol) {
|
||||
for (var id in moduleSymbol.exports) {
|
||||
if (id !== "export=") {
|
||||
@@ -15568,20 +15458,6 @@ namespace ts {
|
||||
return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
|
||||
}
|
||||
|
||||
function instantiateSingleCallFunctionType(functionType: Type, typeArguments: Type[]): Type {
|
||||
if (functionType === unknownType) {
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
const signature = getSingleCallSignature(functionType);
|
||||
if (!signature) {
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
const instantiatedSignature = getSignatureInstantiation(signature, typeArguments);
|
||||
return getOrCreateTypeFromSignature(instantiatedSignature);
|
||||
}
|
||||
|
||||
function createResolver(): EmitResolver {
|
||||
return {
|
||||
getReferencedExportContainer,
|
||||
@@ -16630,25 +16506,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isIntegerLiteral(expression: Expression): boolean {
|
||||
if (expression.kind === SyntaxKind.PrefixUnaryExpression) {
|
||||
const unaryExpression = <PrefixUnaryExpression>expression;
|
||||
if (unaryExpression.operator === SyntaxKind.PlusToken || unaryExpression.operator === SyntaxKind.MinusToken) {
|
||||
expression = unaryExpression.operand;
|
||||
}
|
||||
}
|
||||
if (expression.kind === SyntaxKind.NumericLiteral) {
|
||||
// Allows for scientific notation since literalExpression.text was formed by
|
||||
// coercing a number to a string. Sometimes this coercion can yield a string
|
||||
// in scientific notation.
|
||||
// We also don't need special logic for hex because a hex integer is converted
|
||||
// to decimal when it is coerced.
|
||||
return /^[0-9]+([eE]\+?[0-9]+)?$/.test((<LiteralExpression>expression).text);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function hasParseDiagnostics(sourceFile: SourceFile): boolean {
|
||||
return sourceFile.parseDiagnostics.length > 0;
|
||||
}
|
||||
@@ -16677,11 +16534,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean {
|
||||
return node.kind === SyntaxKind.Identifier &&
|
||||
((<Identifier>node).text === "eval" || (<Identifier>node).text === "arguments");
|
||||
}
|
||||
|
||||
function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
|
||||
if (node.typeParameters) {
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
|
||||
|
||||
@@ -794,23 +794,6 @@ namespace ts {
|
||||
return path;
|
||||
}
|
||||
|
||||
const backslashOrDoubleQuote = /[\"\\]/g;
|
||||
const escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
|
||||
const escapedCharsMap: Map<string> = {
|
||||
"\0": "\\0",
|
||||
"\t": "\\t",
|
||||
"\v": "\\v",
|
||||
"\f": "\\f",
|
||||
"\b": "\\b",
|
||||
"\r": "\\r",
|
||||
"\n": "\\n",
|
||||
"\\": "\\\\",
|
||||
"\"": "\\\"",
|
||||
"\u2028": "\\u2028", // lineSeparator
|
||||
"\u2029": "\\u2029", // paragraphSeparator
|
||||
"\u0085": "\\u0085" // nextLine
|
||||
};
|
||||
|
||||
export interface ObjectAllocator {
|
||||
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
|
||||
getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile;
|
||||
|
||||
@@ -1534,14 +1534,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
function emitBindingElement(bindingElement: BindingElement) {
|
||||
function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
const diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
|
||||
return diagnosticMessage !== undefined ? {
|
||||
diagnosticMessage,
|
||||
errorNode: bindingElement,
|
||||
typeName: bindingElement.name
|
||||
} : undefined;
|
||||
}
|
||||
|
||||
if (bindingElement.kind === SyntaxKind.OmittedExpression) {
|
||||
// If bindingElement is an omittedExpression (i.e. containing elision),
|
||||
|
||||
@@ -779,12 +779,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
|
||||
function emitTrailingCommaIfPresent(nodeList: NodeArray<Node>): void {
|
||||
if (nodeList.hasTrailingComma) {
|
||||
write(",");
|
||||
}
|
||||
}
|
||||
|
||||
function emitLinePreservingList(parent: Node, nodes: NodeArray<Node>, allowTrailingComma: boolean, spacesBetweenBraces: boolean) {
|
||||
Debug.assert(nodes.length > 0);
|
||||
|
||||
@@ -3248,10 +3242,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
|
||||
function emitDownLevelForOfStatement(node: ForOfStatement) {
|
||||
emitLoop(node, emitDownLevelForOfStatementWorker);
|
||||
}
|
||||
|
||||
function emitDownLevelForOfStatementWorker(node: ForOfStatement, loop: ConvertedLoop) {
|
||||
// The following ES6 code:
|
||||
//
|
||||
|
||||
@@ -771,10 +771,6 @@ namespace ts {
|
||||
return doInsideOfContext(ParserContextFlags.Yield, func);
|
||||
}
|
||||
|
||||
function doOutsideOfYieldContext<T>(func: () => T): T {
|
||||
return doOutsideOfContext(ParserContextFlags.Yield, func);
|
||||
}
|
||||
|
||||
function doInDecoratorContext<T>(func: () => T): T {
|
||||
return doInsideOfContext(ParserContextFlags.Decorator, func);
|
||||
}
|
||||
@@ -791,10 +787,6 @@ namespace ts {
|
||||
return doInsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func);
|
||||
}
|
||||
|
||||
function doOutsideOfYieldAndAwaitContext<T>(func: () => T): T {
|
||||
return doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func);
|
||||
}
|
||||
|
||||
function inContext(flags: ParserContextFlags) {
|
||||
return (contextFlags & flags) !== 0;
|
||||
}
|
||||
@@ -851,10 +843,6 @@ namespace ts {
|
||||
return token = scanner.scan();
|
||||
}
|
||||
|
||||
function getTokenPos(pos: number): number {
|
||||
return skipTrivia(sourceText, pos);
|
||||
}
|
||||
|
||||
function reScanGreaterToken(): SyntaxKind {
|
||||
return token = scanner.reScanGreaterToken();
|
||||
}
|
||||
@@ -2644,10 +2632,6 @@ namespace ts {
|
||||
isStartOfExpression();
|
||||
}
|
||||
|
||||
function allowInAndParseExpression(): Expression {
|
||||
return allowInAnd(parseExpression);
|
||||
}
|
||||
|
||||
function parseExpression(): Expression {
|
||||
// Expression[in]:
|
||||
// AssignmentExpression[in]
|
||||
@@ -3962,7 +3946,6 @@ namespace ts {
|
||||
|
||||
const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
|
||||
const tokenIsIdentifier = isIdentifier();
|
||||
const nameToken = token;
|
||||
const propertyName = parsePropertyName();
|
||||
|
||||
// Disallowing of optional property assignments happens in the grammar checker.
|
||||
@@ -5104,10 +5087,6 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseHeritageClausesWorker() {
|
||||
return parseList(ParsingContext.HeritageClauses, parseHeritageClause);
|
||||
}
|
||||
|
||||
function parseHeritageClause() {
|
||||
if (token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword) {
|
||||
const node = <HeritageClause>createNode(SyntaxKind.HeritageClause);
|
||||
@@ -5253,12 +5232,6 @@ namespace ts {
|
||||
return nextToken() === SyntaxKind.SlashToken;
|
||||
}
|
||||
|
||||
function nextTokenIsCommaOrFromKeyword() {
|
||||
nextToken();
|
||||
return token === SyntaxKind.CommaToken ||
|
||||
token === SyntaxKind.FromKeyword;
|
||||
}
|
||||
|
||||
function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration {
|
||||
parseExpected(SyntaxKind.ImportKeyword);
|
||||
const afterImportPos = scanner.getStartPos();
|
||||
@@ -5751,13 +5724,6 @@ namespace ts {
|
||||
return finishNode(parameter);
|
||||
}
|
||||
|
||||
function parseJSDocOptionalType(type: JSDocType): JSDocOptionalType {
|
||||
const result = <JSDocOptionalType>createNode(SyntaxKind.JSDocOptionalType, type.pos);
|
||||
nextToken();
|
||||
result.type = type;
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
function parseJSDocTypeReference(): JSDocTypeReference {
|
||||
const result = <JSDocTypeReference>createNode(SyntaxKind.JSDocTypeReference);
|
||||
result.name = parseSimplePropertyName();
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace ts {
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
const nop = <(...args: any[]) => any>Function.prototype;
|
||||
let nullSourceMapWriter: SourceMapWriter;
|
||||
|
||||
export function getNullSourceMapWriter(): SourceMapWriter {
|
||||
|
||||
@@ -218,7 +218,6 @@ namespace ts {
|
||||
const _fs = require("fs");
|
||||
const _path = require("path");
|
||||
const _os = require("os");
|
||||
const _tty = require("tty");
|
||||
|
||||
// average async stat takes about 30 microseconds
|
||||
// set chunk size to do 30 files in < 1 millisecond
|
||||
@@ -313,10 +312,6 @@ namespace ts {
|
||||
// time dynamically to match the large reference set?
|
||||
const watchedFileSet = createWatchedFileSet();
|
||||
|
||||
function isNode4OrLater(): Boolean {
|
||||
return parseInt(process.version.charAt(1)) >= 4;
|
||||
}
|
||||
|
||||
const platform: string = _os.platform();
|
||||
// win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive
|
||||
const useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin";
|
||||
|
||||
Reference in New Issue
Block a user