Skip to content

Commit

Permalink
Merge branch 'master' into DiagEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
amcasey authored Mar 22, 2018
2 parents 5d54dbe + 810b386 commit f2f4bf0
Show file tree
Hide file tree
Showing 34 changed files with 1,885 additions and 1,756 deletions.
1,178 changes: 486 additions & 692 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "typescript",
"author": "Microsoft Corp.",
"homepage": "http://typescriptlang.org/",
"version": "2.8.0",
"version": "2.9.0",
"license": "Apache-2.0",
"description": "TypeScript is a language for application scale JavaScript development",
"keywords": [
Expand Down
27 changes: 15 additions & 12 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace ts {
let languageVersion: ScriptTarget;
let parent: Node;
let container: Node;
let containerContainer: Node; // Container one level up
let thisParentContainer: Node; // Container one level up
let blockScopeContainer: Node;
let lastContainer: Node;
let seenThisKeyword: boolean;
Expand Down Expand Up @@ -186,7 +186,7 @@ namespace ts {
languageVersion = undefined;
parent = undefined;
container = undefined;
containerContainer = undefined;
thisParentContainer = undefined;
blockScopeContainer = undefined;
lastContainer = undefined;
seenThisKeyword = false;
Expand Down Expand Up @@ -297,7 +297,7 @@ namespace ts {
case SyntaxKind.Parameter:
// Parameters with names are handled at the top of this function. Parameters
// without names can only come from JSDocFunctionTypes.
Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType);
Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType, "Impossible parameter parent kind", () => `parent is: ${(ts as any).SyntaxKind ? (ts as any).SyntaxKind[node.parent.kind] : node.parent.kind}, expected JSDocFunctionType`);
const functionType = <JSDocFunctionType>node.parent;
const index = functionType.parameters.indexOf(node as ParameterDeclaration);
return "arg" + index as __String;
Expand Down Expand Up @@ -479,11 +479,9 @@ namespace ts {
// and block-container. Then after we pop out of processing the children, we restore
// these saved values.
const saveContainer = container;
const saveContainerContainer = containerContainer;
const saveThisParentContainer = thisParentContainer;
const savedBlockScopeContainer = blockScopeContainer;

containerContainer = container;

// Depending on what kind of node this is, we may have to adjust the current container
// and block-container. If the current node is a container, then it is automatically
// considered the current block-container as well. Also, for containers that we know
Expand All @@ -502,6 +500,9 @@ namespace ts {
// for it. We must clear this so we don't accidentally move any stale data forward from
// a previous compilation.
if (containerFlags & ContainerFlags.IsContainer) {
if (node.kind !== SyntaxKind.ArrowFunction) {
thisParentContainer = container;
}
container = blockScopeContainer = node;
if (containerFlags & ContainerFlags.HasLocals) {
container.locals = createSymbolTable();
Expand Down Expand Up @@ -571,7 +572,7 @@ namespace ts {
}

container = saveContainer;
containerContainer = saveContainerContainer;
thisParentContainer = saveThisParentContainer;
blockScopeContainer = savedBlockScopeContainer;
}

Expand Down Expand Up @@ -2338,14 +2339,16 @@ namespace ts {
if (isBinaryExpression(thisContainer.parent) && thisContainer.parent.operatorToken.kind === SyntaxKind.EqualsToken) {
const l = thisContainer.parent.left;
if (isPropertyAccessEntityNameExpression(l) && isPrototypeAccess(l.expression)) {
constructorSymbol = getJSInitializerSymbolFromName(l.expression.expression, containerContainer);
constructorSymbol = getJSInitializerSymbolFromName(l.expression.expression, thisParentContainer);
}
}

// Declare a 'member' if the container is an ES5 class or ES6 constructor
constructorSymbol.members = constructorSymbol.members || createSymbolTable();
// It's acceptable for multiple 'this' assignments of the same identifier to occur
declareSymbol(constructorSymbol.members, constructorSymbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
if (constructorSymbol) {
// Declare a 'member' if the container is an ES5 class or ES6 constructor
constructorSymbol.members = constructorSymbol.members || createSymbolTable();
// It's acceptable for multiple 'this' assignments of the same identifier to occur
declareSymbol(constructorSymbol.members, constructorSymbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
}
break;

case SyntaxKind.Constructor:
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ts {
// WARNING: The script `configureNightly.ts` uses a regexp to parse out these values.
// If changing the text in this section, be sure to test `configureNightly` too.
export const versionMajorMinor = "2.8";
export const versionMajorMinor = "2.9";
/** The version of the TypeScript compiler release */
export const version = `${versionMajorMinor}.0-dev`;
}
Expand Down
16 changes: 3 additions & 13 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7243,17 +7243,17 @@ namespace ts {
forEachChild(sourceFile, visit);

if (lastNodeEntirelyBeforePosition) {
const lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition);
const lastChildOfLastEntireNodeBeforePosition = getLastDescendant(lastNodeEntirelyBeforePosition);
if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) {
bestResult = lastChildOfLastEntireNodeBeforePosition;
}
}

return bestResult;

function getLastChild(node: Node): Node {
function getLastDescendant(node: Node): Node {
while (true) {
const lastChild = getLastChildWorker(node);
const lastChild = getLastChild(node);
if (lastChild) {
node = lastChild;
}
Expand All @@ -7263,16 +7263,6 @@ namespace ts {
}
}

function getLastChildWorker(node: Node): Node | undefined {
let last: Node;
forEachChild(node, child => {
if (nodeIsPresent(child)) {
last = child;
}
});
return last;
}

function visit(child: Node) {
if (nodeIsMissing(child)) {
// Missing nodes are effectively invisible to us. We never even consider them
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ namespace ts {
// Some file or directory in the watching directory is created
// Return early if it does not have any of the watching extension or not the custom failed lookup path
const dirOfFileOrDirectory = getDirectoryPath(fileOrDirectoryPath);
if (isNodeModulesAtTypesDirectory(dirOfFileOrDirectory) || isNodeModulesDirectory(dirOfFileOrDirectory)) {
if (isNodeModulesAtTypesDirectory(fileOrDirectoryPath) || isNodeModulesDirectory(fileOrDirectoryPath) ||
isNodeModulesAtTypesDirectory(dirOfFileOrDirectory) || isNodeModulesDirectory(dirOfFileOrDirectory)) {
// Invalidate any resolution from this directory
isChangedFailedLookupLocation = location => {
const locationPath = resolutionHost.toPath(location);
Expand Down
18 changes: 18 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3883,6 +3883,24 @@ namespace ts {
return isStringLiteral(moduleSpecifier) ? moduleSpecifier.text : getTextOfNode(moduleSpecifier);
}

export function getLastChild(node: Node): Node | undefined {
let lastChild: Node | undefined;
forEachChild(node,
child => {
if (nodeIsPresent(child)) lastChild = child;
},
children => {
// As an optimization, jump straight to the end of the list.
for (let i = children.length - 1; i >= 0; i--) {
if (nodeIsPresent(children[i])) {
lastChild = children[i];
break;
}
}
});
return lastChild;
}

/** Add a value to a set, and return true if it wasn't already present. */
export function addToSeen(seen: Map<true>, key: string | number): boolean {
key = String(key);
Expand Down
2 changes: 1 addition & 1 deletion src/harness/parallel/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ namespace Harness.Parallel.Host {
};
}

describe = ts.noop as any; // Disable unit tests
(global as any).describe = ts.noop as any; // Disable unit tests

return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/harness/parallel/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace Harness.Parallel.Worker {
(global as any).before = undefined;
(global as any).after = undefined;
(global as any).beforeEach = undefined;
describe = ((name, callback) => {
(global as any).describe = ((name, callback) => {
testList.push({ name, callback, kind: "suite" });
}) as Mocha.IContextDefinition;
it = ((name, callback) => {
(global as any).it = ((name, callback) => {
if (!testList) {
throw new Error("Tests must occur within a describe block");
}
Expand Down Expand Up @@ -251,7 +251,7 @@ namespace Harness.Parallel.Worker {
});
if (!runUnitTests) {
// ensure unit tests do not get run
describe = ts.noop as any;
(global as any).describe = ts.noop;
}
else {
initialized = true;
Expand Down
2 changes: 1 addition & 1 deletion src/harness/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function beginTests() {

if (!runUnitTests) {
// patch `describe` to skip unit tests
describe = ts.noop as any;
(global as any).describe = ts.noop;
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/harness/unittests/organizeImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ export const Other = 1;
assert.isEmpty(changes);
});

testOrganizeImports("Renamed_used",
{
path: "/test.ts",
content: `
import { F1 as EffOne, F2 as EffTwo } from "lib";
EffOne();
`,
},
libFile);

testOrganizeImports("Simple",
{
path: "/test.ts",
Expand Down
82 changes: 43 additions & 39 deletions src/harness/unittests/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,43 @@ namespace ts {
const printsCorrectly = makePrintsCorrectly("printsFileCorrectly");
// Avoid eagerly creating the sourceFile so that `createSourceFile` doesn't run unless one of these tests is run.
let sourceFile: SourceFile;
before(() => sourceFile = createSourceFile("source.ts", `
interface A<T> {
// comment1
readonly prop?: T;
before(() => {
sourceFile = createSourceFile("source.ts", `
interface A<T> {
// comment1
readonly prop?: T;
// comment2
method(): void;
// comment2
method(): void;
// comment3
new <T>(): A<T>;
// comment3
new <T>(): A<T>;
// comment4
<T>(): A<T>;
}
// comment4
<T>(): A<T>;
}
// comment5
type B = number | string | object;
type C = A<number> & { x: string; }; // comment6
// comment5
type B = number | string | object;
type C = A<number> & { x: string; }; // comment6
// comment7
enum E1 {
// comment8
first
}
// comment7
enum E1 {
// comment8
first
}
const enum E2 {
second
}
const enum E2 {
second
}
// comment9
console.log(1 + 2);
// comment9
console.log(1 + 2);
// comment10
function functionWithDefaultArgValue(argument: string = "defaultValue"): void { }
`, ScriptTarget.ES2015));
// comment10
function functionWithDefaultArgValue(argument: string = "defaultValue"): void { }
`, ScriptTarget.ES2015);
});
printsCorrectly("default", {}, printer => printer.printFile(sourceFile));
printsCorrectly("removeComments", { removeComments: true }, printer => printer.printFile(sourceFile));

Expand All @@ -65,20 +67,22 @@ namespace ts {
describe("printBundle", () => {
const printsCorrectly = makePrintsCorrectly("printsBundleCorrectly");
let bundle: Bundle;
before(() => bundle = createBundle([
createSourceFile("a.ts", `
/*! [a.ts] */
before(() => {
bundle = createBundle([
createSourceFile("a.ts", `
/*! [a.ts] */
// comment0
const a = 1;
`, ScriptTarget.ES2015),
createSourceFile("b.ts", `
/*! [b.ts] */
// comment0
const a = 1;
`, ScriptTarget.ES2015),
createSourceFile("b.ts", `
/*! [b.ts] */
// comment1
const b = 2;
`, ScriptTarget.ES2015)
]));
// comment1
const b = 2;
`, ScriptTarget.ES2015)
]);
});
printsCorrectly("default", {}, printer => printer.printBundle(bundle));
printsCorrectly("removeComments", { removeComments: true }, printer => printer.printBundle(bundle));
});
Expand Down
22 changes: 22 additions & 0 deletions src/harness/unittests/tscWatchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,28 @@ declare module "fs" {
};
}
});

it("works when renaming node_modules folder that already contains @types folder", () => {
const currentDirectory = "/user/username/projects/myproject";
const file: FileOrFolder = {
path: `${currentDirectory}/a.ts`,
content: `import * as q from "qqq";`
};
const module: FileOrFolder = {
path: `${currentDirectory}/node_modules2/@types/qqq/index.d.ts`,
content: "export {}"
};
const files = [file, module, libFile];
const host = createWatchedSystem(files, { currentDirectory });
const watch = createWatchOfFilesAndCompilerOptions([file.path], host);
checkProgramActualFiles(watch(), [file.path, libFile.path]);
checkOutputErrorsInitial(host, [getDiagnosticModuleNotFoundOfFile(watch(), file, "qqq")]);

host.renameFolder(`${currentDirectory}/node_modules2`, `${currentDirectory}/node_modules`);
host.runQueuedTimeoutCallbacks();
checkProgramActualFiles(watch(), [file.path, libFile.path, `${currentDirectory}/node_modules/@types/qqq/index.d.ts`]);
checkOutputErrorsIncremental(host, emptyArray);
});
});

describe("tsc-watch with when module emit is specified as node", () => {
Expand Down
16 changes: 12 additions & 4 deletions src/harness/virtualFileSystemWithWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,24 @@ interface Array<T> {}`
this.addFileOrFolderInFolder(baseFolder, newFolder);

// Invoke watches for files in the folder as deleted (from old path)
for (const entry of folder.entries) {
Debug.assert(isFile(entry));
this.renameFolderEntries(folder, newFolder);
}

private renameFolderEntries(oldFolder: Folder, newFolder: Folder) {
for (const entry of oldFolder.entries) {
this.fs.delete(entry.path);
this.invokeFileWatcher(entry.fullPath, FileWatcherEventKind.Deleted);

entry.fullPath = combinePaths(newFullPath, getBaseFileName(entry.fullPath));
entry.fullPath = combinePaths(newFolder.fullPath, getBaseFileName(entry.fullPath));
entry.path = this.toPath(entry.fullPath);
newFolder.entries.push(entry);
if (newFolder !== oldFolder) {
newFolder.entries.push(entry);
}
this.fs.set(entry.path, entry);
this.invokeFileWatcher(entry.fullPath, FileWatcherEventKind.Created);
if (isFolder(entry)) {
this.renameFolderEntries(entry, entry);
}
}
}

Expand Down
Loading

0 comments on commit f2f4bf0

Please sign in to comment.