diff --git a/package.json b/package.json index 1f943f89788..3297788667c 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "ts-node": "latest", "tsd": "latest", "tslint": "next", - "typescript": "next" + "typescript": "2.1.0-dev.20160906" }, "scripts": { "pretest": "jake tests", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f7b92b643ca..d880b6b567b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -435,6 +435,8 @@ namespace ts { TypeExcludesFlags = YieldContext | AwaitContext, } + export type ModifiersArray = NodeArray; + export const enum ModifierFlags { None = 0, Export = 1 << 0, // Declarations @@ -480,7 +482,7 @@ namespace ts { /* @internal */ modifierFlagsCache?: ModifierFlags; /* @internal */ transformFlags?: TransformFlags; decorators?: NodeArray; // Array of decorators (in document order) - modifiers?: NodeArray; // Array of modifiers + modifiers?: ModifiersArray; // Array of modifiers /* @internal */ id?: number; // Unique id (used to look up NodeLinks) parent?: Node; // Parent node (initialized by binding) /* @internal */ original?: Node; // The original node if this is an updated node. diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 2b734c98044..9ea74abbf76 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -596,60 +596,6 @@ namespace ts { return node.kind === SyntaxKind.EnumDeclaration && isConst(node); } - function walkUpBindingElementsAndPatterns(node: Node): Node { - while (node && (node.kind === SyntaxKind.BindingElement || isBindingPattern(node))) { - node = node.parent; - } - - return node; - } - - export function getCombinedModifierFlags(node: Node): ModifierFlags { - node = walkUpBindingElementsAndPatterns(node); - let flags = getModifierFlags(node); - if (node.kind === SyntaxKind.VariableDeclaration) { - node = node.parent; - } - - if (node && node.kind === SyntaxKind.VariableDeclarationList) { - flags |= getModifierFlags(node); - node = node.parent; - } - - if (node && node.kind === SyntaxKind.VariableStatement) { - flags |= getModifierFlags(node); - } - - return flags; - } - - // Returns the node flags for this node and all relevant parent nodes. This is done so that - // nodes like variable declarations and binding elements can returned a view of their flags - // that includes the modifiers from their container. i.e. flags like export/declare aren't - // stored on the variable declaration directly, but on the containing variable statement - // (if it has one). Similarly, flags for let/const are store on the variable declaration - // list. By calling this function, all those flags are combined so that the client can treat - // the node as if it actually had those flags. - export function getCombinedNodeFlags(node: Node): NodeFlags { - node = walkUpBindingElementsAndPatterns(node); - - let flags = node.flags; - if (node.kind === SyntaxKind.VariableDeclaration) { - node = node.parent; - } - - if (node && node.kind === SyntaxKind.VariableDeclarationList) { - flags |= node.flags; - node = node.parent; - } - - if (node && node.kind === SyntaxKind.VariableStatement) { - flags |= node.flags; - } - - return flags; - } - export function isConst(node: Node): boolean { return !!(getCombinedNodeFlags(node) & NodeFlags.Const) || !!(getCombinedModifierFlags(node) & ModifierFlags.Const); @@ -4370,4 +4316,58 @@ namespace ts { export function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean { return hasModifier(node, ModifierFlags.ParameterPropertyModifier) && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent); } + + function walkUpBindingElementsAndPatterns(node: Node): Node { + while (node && (node.kind === SyntaxKind.BindingElement || isBindingPattern(node))) { + node = node.parent; + } + + return node; + } + + export function getCombinedModifierFlags(node: Node): ModifierFlags { + node = walkUpBindingElementsAndPatterns(node); + let flags = getModifierFlags(node); + if (node.kind === SyntaxKind.VariableDeclaration) { + node = node.parent; + } + + if (node && node.kind === SyntaxKind.VariableDeclarationList) { + flags |= getModifierFlags(node); + node = node.parent; + } + + if (node && node.kind === SyntaxKind.VariableStatement) { + flags |= getModifierFlags(node); + } + + return flags; + } + + // Returns the node flags for this node and all relevant parent nodes. This is done so that + // nodes like variable declarations and binding elements can returned a view of their flags + // that includes the modifiers from their container. i.e. flags like export/declare aren't + // stored on the variable declaration directly, but on the containing variable statement + // (if it has one). Similarly, flags for let/const are store on the variable declaration + // list. By calling this function, all those flags are combined so that the client can treat + // the node as if it actually had those flags. + export function getCombinedNodeFlags(node: Node): NodeFlags { + node = walkUpBindingElementsAndPatterns(node); + + let flags = node.flags; + if (node.kind === SyntaxKind.VariableDeclaration) { + node = node.parent; + } + + if (node && node.kind === SyntaxKind.VariableDeclarationList) { + flags |= node.flags; + node = node.parent; + } + + if (node && node.kind === SyntaxKind.VariableStatement) { + flags |= node.flags; + } + + return flags; + } } diff --git a/src/services/completions.ts b/src/services/completions.ts index 6ea24e36025..e0130899e3d 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -578,8 +578,8 @@ namespace ts.Completions { if (host.getDirectories) { // Also get all @types typings installed in visible node_modules directories - for (const package of findPackageJsons(scriptPath)) { - const typesDir = combinePaths(getDirectoryPath(package), "node_modules/@types"); + for (const packageJson of findPackageJsons(scriptPath)) { + const typesDir = combinePaths(getDirectoryPath(packageJson), "node_modules/@types"); getCompletionEntriesFromDirectories(host, options, typesDir, span, result); } } @@ -625,8 +625,8 @@ namespace ts.Completions { if (host.readFile && host.fileExists) { for (const packageJson of findPackageJsons(scriptPath)) { - const package = tryReadingPackageJson(packageJson); - if (!package) { + const contents = tryReadingPackageJson(packageJson); + if (!contents) { return; } @@ -635,7 +635,7 @@ namespace ts.Completions { // Provide completions for all non @types dependencies for (const key of nodeModulesDependencyKeys) { - addPotentialPackageNames(package[key], foundModuleNames); + addPotentialPackageNames(contents[key], foundModuleNames); } for (const moduleName of foundModuleNames) {