Merge branch 'master' into typeof-can-refer-class-before-declaration

This commit is contained in:
Nathan Shively-Sanders
2017-04-17 15:30:16 -07:00
23 changed files with 291 additions and 5 deletions

View File

@@ -760,11 +760,17 @@ namespace ts {
// declaration is after usage, but it can still be legal if usage is deferred:
// 1. inside a function
// 2. inside an instance property initializer, a reference to a non-instance property
// 3. inside a static property initializer, a reference to a static method in the same class
// 1. inside an export specifier
// 2. inside a function
// 3. inside an instance property initializer, a reference to a non-instance property
// 4. inside a static property initializer, a reference to a static method in the same class
// or if usage is in a type context:
// 1. inside a type query (typeof in type position)
if (usage.parent.kind === SyntaxKind.ExportSpecifier) {
// export specifiers do not use the variable, they only make it available for use
return true;
}
const container = getEnclosingBlockScopeContainer(declaration);
return isInTypeQuery(usage) || isUsedInFunctionOrInstanceProperty(usage, declaration, container);

View File

@@ -3185,6 +3185,10 @@
"category": "Message",
"code": 6181
},
"Scoped package detected, looking in '{0}'": {
"category": "Message",
"code": "6182"
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",

View File

@@ -954,10 +954,25 @@ namespace ts {
}
nodeModulesAtTypesExists = false;
}
return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, moduleName, nodeModulesAtTypes, nodeModulesAtTypesExists, failedLookupLocations, state);
return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, mangleScopedPackage(moduleName, state), nodeModulesAtTypes, nodeModulesAtTypesExists, failedLookupLocations, state);
}
}
/** For a scoped package, we must look in `@types/foo__bar` instead of `@types/@foo/bar`. */
function mangleScopedPackage(moduleName: string, state: ModuleResolutionState): string {
if (startsWith(moduleName, "@")) {
const replaceSlash = moduleName.replace(ts.directorySeparator, "__");
if (replaceSlash !== moduleName) {
const mangled = replaceSlash.slice(1); // Take off the "@"
if (state.traceEnabled) {
trace(state.host, Diagnostics.Scoped_package_detected_looking_in_0, mangled);
}
return mangled;
}
}
return moduleName;
}
function tryFindNonRelativeModuleNameInCache(cache: PerModuleNameCache | undefined, moduleName: string, containingDirectory: string, traceEnabled: boolean, host: ModuleResolutionHost): SearchResult<Resolved> {
const result = cache && cache.get(containingDirectory);
if (result) {

View File

@@ -401,7 +401,9 @@ namespace ts.server {
byteLength: Buffer.byteLength,
hrtime: process.hrtime,
logger,
canUseEvents});
canUseEvents,
globalPlugins: options.globalPlugins,
pluginProbeLocations: options.pluginProbeLocations});
if (telemetryEnabled && typingsInstaller) {
typingsInstaller.setTelemetrySender(this);

View File

@@ -0,0 +1,19 @@
//// [exportBinding.ts]
export { x }
const x = 'x'
export { Y as Z }
class Y {}
//// [exportBinding.js]
"use strict";
exports.__esModule = true;
var x = 'x';
exports.x = x;
var Y = (function () {
function Y() {
}
return Y;
}());
exports.Z = Y;

View File

@@ -0,0 +1,14 @@
=== tests/cases/conformance/es6/modules/exportBinding.ts ===
export { x }
>x : Symbol(x, Decl(exportBinding.ts, 0, 8))
const x = 'x'
>x : Symbol(x, Decl(exportBinding.ts, 1, 5))
export { Y as Z }
>Y : Symbol(Z, Decl(exportBinding.ts, 3, 8))
>Z : Symbol(Z, Decl(exportBinding.ts, 3, 8))
class Y {}
>Y : Symbol(Y, Decl(exportBinding.ts, 3, 17))

View File

@@ -0,0 +1,15 @@
=== tests/cases/conformance/es6/modules/exportBinding.ts ===
export { x }
>x : "x"
const x = 'x'
>x : "x"
>'x' : "x"
export { Y as Z }
>Y : typeof Y
>Z : typeof Y
class Y {}
>Y : Y

View File

@@ -0,0 +1,11 @@
//// [tests/cases/conformance/references/library-reference-scoped-packages.ts] ////
//// [index.d.ts]
export const y = 0;
//// [a.ts]
/// <reference types="@beep/boop" />
//// [a.js]
/// <reference types="@beep/boop" />

View File

@@ -0,0 +1,7 @@
=== /a.ts ===
/// <reference types="@beep/boop" />
No type information for this code.
No type information for this code.=== /node_modules/@types/beep__boop/index.d.ts ===
export const y = 0;
>y : Symbol(y, Decl(index.d.ts, 0, 12))

View File

@@ -0,0 +1,12 @@
[
"======== Resolving type reference directive '@beep/boop', containing file '/a.ts', root directory 'types'. ========",
"Resolving with primary search path 'types'.",
"Directory 'types/@beep' does not exist, skipping all lookups in it.",
"Looking up in 'node_modules' folder, initial location '/'.",
"Scoped package detected, looking in 'beep__boop'",
"File '/node_modules/@types/beep__boop.d.ts' does not exist.",
"File '/node_modules/@types/beep__boop/package.json' does not exist.",
"File '/node_modules/@types/beep__boop/index.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/@types/beep__boop/index.d.ts', result '/node_modules/@types/beep__boop/index.d.ts'.",
"======== Type reference directive '@beep/boop' was successfully resolved to '/node_modules/@types/beep__boop/index.d.ts', primary: false. ========"
]

View File

@@ -0,0 +1,8 @@
=== /a.ts ===
/// <reference types="@beep/boop" />
No type information for this code.
No type information for this code.=== /node_modules/@types/beep__boop/index.d.ts ===
export const y = 0;
>y : 0
>0 : 0

View File

@@ -0,0 +1,20 @@
//// [tests/cases/conformance/moduleResolution/scopedPackages.ts] ////
//// [index.d.ts]
export const x: number;
//// [index.d.ts]
export const y: number;
//// [z.d.ts]
export const z: number;
//// [a.ts]
import { x } from "@cow/boy";
import { y } from "@be/bop";
import { z } from "@be/bop/e/z";
//// [a.js]
"use strict";
exports.__esModule = true;

View File

@@ -0,0 +1,22 @@
=== /a.ts ===
import { x } from "@cow/boy";
>x : Symbol(x, Decl(a.ts, 0, 8))
import { y } from "@be/bop";
>y : Symbol(y, Decl(a.ts, 1, 8))
import { z } from "@be/bop/e/z";
>z : Symbol(z, Decl(a.ts, 2, 8))
=== /node_modules/@cow/boy/index.d.ts ===
export const x: number;
>x : Symbol(x, Decl(index.d.ts, 0, 12))
=== /node_modules/@types/be__bop/index.d.ts ===
export const y: number;
>y : Symbol(y, Decl(index.d.ts, 0, 12))
=== /node_modules/@types/be__bop/e/z.d.ts ===
export const z: number;
>z : Symbol(z, Decl(z.d.ts, 0, 12))

View File

@@ -0,0 +1,30 @@
[
"======== Resolving module '@cow/boy' from '/a.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module '@cow/boy' from 'node_modules' folder, target file type 'TypeScript'.",
"File '/node_modules/@cow/boy.ts' does not exist.",
"File '/node_modules/@cow/boy.tsx' does not exist.",
"File '/node_modules/@cow/boy.d.ts' does not exist.",
"File '/node_modules/@cow/boy/package.json' does not exist.",
"File '/node_modules/@cow/boy/index.ts' does not exist.",
"File '/node_modules/@cow/boy/index.tsx' does not exist.",
"File '/node_modules/@cow/boy/index.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/@cow/boy/index.d.ts', result '/node_modules/@cow/boy/index.d.ts'.",
"======== Module name '@cow/boy' was successfully resolved to '/node_modules/@cow/boy/index.d.ts'. ========",
"======== Resolving module '@be/bop' from '/a.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module '@be/bop' from 'node_modules' folder, target file type 'TypeScript'.",
"Scoped package detected, looking in 'be__bop'",
"File '/node_modules/@types/be__bop.d.ts' does not exist.",
"File '/node_modules/@types/be__bop/package.json' does not exist.",
"File '/node_modules/@types/be__bop/index.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/@types/be__bop/index.d.ts', result '/node_modules/@types/be__bop/index.d.ts'.",
"======== Module name '@be/bop' was successfully resolved to '/node_modules/@types/be__bop/index.d.ts'. ========",
"======== Resolving module '@be/bop/e/z' from '/a.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module '@be/bop/e/z' from 'node_modules' folder, target file type 'TypeScript'.",
"Scoped package detected, looking in 'be__bop/e/z'",
"File '/node_modules/@types/be__bop/e/z.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/@types/be__bop/e/z.d.ts', result '/node_modules/@types/be__bop/e/z.d.ts'.",
"======== Module name '@be/bop/e/z' was successfully resolved to '/node_modules/@types/be__bop/e/z.d.ts'. ========"
]

View File

@@ -0,0 +1,22 @@
=== /a.ts ===
import { x } from "@cow/boy";
>x : number
import { y } from "@be/bop";
>y : number
import { z } from "@be/bop/e/z";
>z : number
=== /node_modules/@cow/boy/index.d.ts ===
export const x: number;
>x : number
=== /node_modules/@types/be__bop/index.d.ts ===
export const y: number;
>y : number
=== /node_modules/@types/be__bop/e/z.d.ts ===
export const z: number;
>z : number

View File

@@ -0,0 +1,12 @@
//// [tests/cases/conformance/moduleResolution/scopedPackagesClassic.ts] ////
//// [index.d.ts]
export const x = 0;
//// [a.ts]
import { x } from "@see/saw";
//// [a.js]
"use strict";
exports.__esModule = true;

View File

@@ -0,0 +1,8 @@
=== /a.ts ===
import { x } from "@see/saw";
>x : Symbol(x, Decl(a.ts, 0, 8))
=== /node_modules/@types/see__saw/index.d.ts ===
export const x = 0;
>x : Symbol(x, Decl(index.d.ts, 0, 12))

View File

@@ -0,0 +1,9 @@
[
"======== Resolving module '@see/saw' from '/a.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"Scoped package detected, looking in 'see__saw'",
"File '/node_modules/@types/see__saw.d.ts' does not exist.",
"File '/node_modules/@types/see__saw/package.json' does not exist.",
"File '/node_modules/@types/see__saw/index.d.ts' exist - use it as a name resolution result.",
"======== Module name '@see/saw' was successfully resolved to '/node_modules/@types/see__saw/index.d.ts'. ========"
]

View File

@@ -0,0 +1,9 @@
=== /a.ts ===
import { x } from "@see/saw";
>x : 0
=== /node_modules/@types/see__saw/index.d.ts ===
export const x = 0;
>x : 0
>0 : 0

View File

@@ -0,0 +1,5 @@
export { x }
const x = 'x'
export { Y as Z }
class Y {}

View File

@@ -0,0 +1,17 @@
// @noImplicitReferences: true
// @traceResolution: true
// @typeRoots: types
// @filename: /node_modules/@cow/boy/index.d.ts
export const x: number;
// @filename: /node_modules/@types/be__bop/index.d.ts
export const y: number;
// @filename: /node_modules/@types/be__bop/e/z.d.ts
export const z: number;
// @filename: /a.ts
import { x } from "@cow/boy";
import { y } from "@be/bop";
import { z } from "@be/bop/e/z";

View File

@@ -0,0 +1,10 @@
// @noImplicitReferences: true
// @traceResolution: true
// @typeRoots: types
// @moduleResolution: classic
// @filename: /node_modules/@types/see__saw/index.d.ts
export const x = 0;
// @filename: /a.ts
import { x } from "@see/saw";

View File

@@ -0,0 +1,9 @@
// @noImplicitReferences: true
// @traceResolution: true
// @typeRoots: types
// @filename: /node_modules/@types/beep__boop/index.d.ts
export const y = 0;
// @filename: /a.ts
/// <reference types="@beep/boop" />