Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into debug-messages
Browse files Browse the repository at this point in the history
* origin/master: (64 commits)
  Fix resolution of properties from prototype assignment in JS (microsoft#29302)
  Include all flow nodes made within `try` blocks as antecedents for `catch` or `finally` blocks (microsoft#29466)
  Don't treat interfaces as implementations
  Make the relationship between partial mapped types and the empty object not apply for subtype relationship (microsoft#29384)
  Add missing arity check on second inference pass (microsoft#29386)
  renames
  add missing type annotation
  PR feedback
  Illustrate a case that isn't handled correctly
  Add fourslash tests
  Consider JSX namespace imports when moving statements between files
  Fix gulp builds not building some targets
  Update user baselines (microsoft#29444)
  Add opt-in user preference for prefix and suffix text on renames (microsoft#29314)
  Fake up value declaration for synthetic jsx children symbol so they get excess property checked (microsoft#29359)
  Add regression test. (microsoft#29433)
  Elaborate jsx children elementwise (microsoft#29264)
  Add regression test
  PR feedback
  Fix trailing whitespace
  ...
  • Loading branch information
errendir committed Jan 20, 2019
2 parents a4c10a4 + 3a2f6a3 commit f62e3b0
Show file tree
Hide file tree
Showing 181 changed files with 5,183 additions and 3,121 deletions.
63 changes: 36 additions & 27 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,29 +488,28 @@ gulp.task(
"Runs 'local'",
["local"]);

gulp.task(
"watch-diagnostics",
/*help*/ false,
[processDiagnosticMessagesJs],
() => gulp.watch([diagnosticMessagesJson], [diagnosticInformationMapTs, builtGeneratedDiagnosticMessagesJson]));

gulp.task(
"watch-lib",
/*help*/ false,
() => gulp.watch(["src/lib/**/*"], ["lib"]));

const watchTscPatterns = [
"src/tsconfig-base.json",
"src/lib/**/*",
"src/compiler/**/*",
"src/tsc/**/*",
];
gulp.task(
"watch-tsc",
/*help*/ false,
["watch-diagnostics", "watch-lib"].concat(useCompilerDeps),
() => project.watch(tscProject, { typescript: useCompiler }));
useCompilerDeps,
() => gulp.watch(watchTscPatterns, ["tsc"]));

const watchServicesPatterns = [
"src/compiler/**/*",
"src/jsTypings/**/*",
"src/services/**/*"
];

gulp.task(
"watch-services",
/*help*/ false,
Expand All @@ -522,39 +521,49 @@ const watchLsslPatterns = [
"src/server/**/*",
"src/tsserver/tsconfig.json"
];

gulp.task(
"watch-lssl",
/*help*/ false,
() => gulp.watch(watchLsslPatterns, ["lssl"]));

gulp.task(
"watch-server",
/*help*/ false,
["watch-diagnostics", "watch-lib"].concat(useCompilerDeps),
() => project.watch(tsserverProject, { typescript: useCompiler }));

gulp.task(
"watch-runner",
/*help*/ false,
useCompilerDeps,
() => project.watch(testRunnerProject, { typescript: useCompiler }));

const watchLocalPatterns = [
"src/tsconfig-base.json",
"src/lib/**/*",
"src/compiler/**/*",
"src/tsc/**/*",
"src/services/**/*",
"src/jsTyping/**/*",
"src/server/**/*",
"src/tsserver/**/*",
"src/typingsInstallerCore/**/*",
"src/harness/**/*",
"src/testRunner/**/*",
];
gulp.task(
"watch-local",
"Watches for changes to projects in src/ (but does not execute tests).",
["watch-lib", "watch-tsc", "watch-services", "watch-server", "watch-runner", "watch-lssl"]);
() => gulp.watch(watchLocalPatterns, "local"));

const watchPatterns = [
"src/tsconfig-base.json",
"src/lib/**/*",
"src/compiler/**/*",
"src/services/**/*",
"src/jsTyping/**/*",
"src/server/**/*",
"src/tsserver/**/*",
"src/typingsInstallerCore/**/*",
"src/harness/**/*",
"src/testRunner/**/*",
];
gulp.task(
"watch",
"Watches for changes to the build inputs for built/local/run.js, then runs tests.",
["build-rules", "watch-runner", "watch-services", "watch-lssl"],
["build-rules"],
() => {
const sem = new Semaphore(1);

gulp.watch([runJs, typescriptDts, tsserverlibraryDts], () => {
runTests();
});
gulp.watch(watchPatterns, () => { runTests(); });

// NOTE: gulp.watch is far too slow when watching tests/cases/**/* as it first enumerates *every* file
const testFilePattern = /(\.ts|[\\/]tsconfig\.json)$/;
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = minimist(process.argv.slice(2), {
workers: process.env.workerCount || os.cpus().length,
failed: false,
keepFailed: false,
lkg: false,
lkg: true,
dirty: false
}
});
Expand Down
106 changes: 39 additions & 67 deletions scripts/build/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,78 +14,54 @@ const ts = require("../../lib/typescript");
const del = require("del");
const needsUpdate = require("./needsUpdate");
const mkdirp = require("./mkdirp");
const prettyTime = require("pretty-hrtime");
const { reportDiagnostics } = require("./diagnostics");
const { CountdownEvent, ManualResetEvent } = require("prex");
const { CountdownEvent, ManualResetEvent, Semaphore } = require("prex");

const workStartedEvent = new ManualResetEvent();
const countdown = new CountdownEvent(0);

class CompilationGulp extends gulp.Gulp {
/**
* @param {boolean} [verbose]
*/
fork(verbose) {
const child = new ForkedGulp(this.tasks);
child.on("task_start", e => {
if (countdown.remainingCount === 0) {
countdown.reset(1);
workStartedEvent.set();
workStartedEvent.reset();
}
else {
countdown.add();
}
if (verbose) {
log('Starting', `'${chalk.cyan(e.task)}' ${chalk.gray(`(${countdown.remainingCount} remaining)`)}...`);
}
});
child.on("task_stop", e => {
countdown.signal();
if (verbose) {
log('Finished', `'${chalk.cyan(e.task)}' after ${chalk.magenta(prettyTime(/** @type {*}*/(e).hrDuration))} ${chalk.gray(`(${countdown.remainingCount} remaining)`)}`);
}
});
child.on("task_err", e => {
countdown.signal();
if (verbose) {
log(`'${chalk.cyan(e.task)}' ${chalk.red("errored after")} ${chalk.magenta(prettyTime(/** @type {*}*/(e).hrDuration))} ${chalk.gray(`(${countdown.remainingCount} remaining)`)}`);
log(e.err ? e.err.stack : e.message);
}
});
return child;
}

// @ts-ignore
start() {
throw new Error("Not supported, use fork.");
}
}

class ForkedGulp extends gulp.Gulp {
/**
* @param {gulp.Gulp["tasks"]} tasks
*/
constructor(tasks) {
super();
this.tasks = tasks;
}

// Do not reset tasks
_resetAllTasks() {}
_resetSpecificTasks() {}
_resetTask() {}
}

// internal `Gulp` instance for compilation artifacts.
const compilationGulp = new CompilationGulp();
const compilationGulp = new gulp.Gulp();

/** @type {Map<ResolvedProjectSpec, ProjectGraph>} */
const projectGraphCache = new Map();

/** @type {Map<string, { typescript: string, alias: string, paths: ResolvedPathOptions }>} */
const typescriptAliasMap = new Map();

// TODO: allow concurrent outer builds to be run in parallel
const sem = new Semaphore(1);

/**
* @param {string|string[]} taskName
* @param {() => any} [cb]
*/
function start(taskName, cb) {
return sem.wait().then(() => new Promise((resolve, reject) => {
compilationGulp.start(taskName, err => {
if (err) {
reject(err);
}
else if (cb) {
try {
resolve(cb());
}
catch (e) {
reject(err);
}
}
else {
resolve();
}
});
})).then(() => {
sem.release()
}, e => {
sem.release();
throw e;
});
}

/**
* Defines a gulp orchestration for a TypeScript project, returning a callback that can be used to trigger compilation.
* @param {string} projectSpec The path to a tsconfig.json file or its containing directory.
Expand All @@ -98,9 +74,7 @@ function createCompiler(projectSpec, options) {
const projectGraph = getOrCreateProjectGraph(resolvedProjectSpec, resolvedOptions.paths);
projectGraph.isRoot = true;
const taskName = compileTaskName(ensureCompileTask(projectGraph, resolvedOptions), resolvedOptions.typescript);
return () => new Promise((resolve, reject) => compilationGulp
.fork(resolvedOptions.verbose)
.start(taskName, err => err ? reject(err) : resolve()));
return () => start(taskName);
}
exports.createCompiler = createCompiler;

Expand Down Expand Up @@ -139,9 +113,7 @@ function createCleaner(projectSpec, options) {
const projectGraph = getOrCreateProjectGraph(resolvedProjectSpec, paths);
projectGraph.isRoot = true;
const taskName = cleanTaskName(ensureCleanTask(projectGraph));
return () => new Promise((resolve, reject) => compilationGulp
.fork()
.start(taskName, err => err ? reject(err) : resolve()));
return () => start(taskName);
}
exports.createCleaner = createCleaner;

Expand Down Expand Up @@ -811,7 +783,7 @@ function possiblyTriggerRecompilation(config, task) {
function triggerRecompilation(task, config) {
compilationGulp._resetTask(task);
if (config.watchers && config.watchers.size) {
compilationGulp.fork().start(task.name, () => {
start(task.name, () => {
/** @type {Set<string>} */
const taskNames = new Set();
/** @type {((err?: any) => void)[]} */
Expand All @@ -831,7 +803,7 @@ function triggerRecompilation(task, config) {
});
}
else {
compilationGulp.fork(/*verbose*/ true).start(task.name);
start(task.name);
}
}

Expand Down
45 changes: 39 additions & 6 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ namespace ts {
IsObjectLiteralOrClassExpressionMethod = 1 << 7,
}

let flowNodeCreated: <T extends FlowNode>(node: T) => T = identity;

const binder = createBinder();

export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
Expand Down Expand Up @@ -530,6 +532,7 @@ namespace ts {
blockScopeContainer.locals = undefined;
}
if (containerFlags & ContainerFlags.IsControlFlowContainer) {
const saveFlowNodeCreated = flowNodeCreated;
const saveCurrentFlow = currentFlow;
const saveBreakTarget = currentBreakTarget;
const saveContinueTarget = currentContinueTarget;
Expand All @@ -553,6 +556,7 @@ namespace ts {
currentContinueTarget = undefined;
activeLabels = undefined;
hasExplicitReturn = false;
flowNodeCreated = identity;
bindChildren(node);
// Reset all reachability check related flags on node (for incremental scenarios)
node.flags &= ~NodeFlags.ReachabilityAndEmitFlags;
Expand All @@ -579,6 +583,7 @@ namespace ts {
currentReturnTarget = saveReturnTarget;
activeLabels = saveActiveLabels;
hasExplicitReturn = saveHasExplicitReturn;
flowNodeCreated = saveFlowNodeCreated;
}
else if (containerFlags & ContainerFlags.IsInterface) {
seenThisKeyword = false;
Expand Down Expand Up @@ -858,25 +863,25 @@ namespace ts {
return antecedent;
}
setFlowNodeReferenced(antecedent);
return { flags, expression, antecedent };
return flowNodeCreated({ flags, expression, antecedent });
}

function createFlowSwitchClause(antecedent: FlowNode, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number): FlowNode {
if (!isNarrowingExpression(switchStatement.expression)) {
return antecedent;
}
setFlowNodeReferenced(antecedent);
return { flags: FlowFlags.SwitchClause, switchStatement, clauseStart, clauseEnd, antecedent };
return flowNodeCreated({ flags: FlowFlags.SwitchClause, switchStatement, clauseStart, clauseEnd, antecedent });
}

function createFlowAssignment(antecedent: FlowNode, node: Expression | VariableDeclaration | BindingElement): FlowNode {
setFlowNodeReferenced(antecedent);
return { flags: FlowFlags.Assignment, antecedent, node };
return flowNodeCreated({ flags: FlowFlags.Assignment, antecedent, node });
}

function createFlowArrayMutation(antecedent: FlowNode, node: CallExpression | BinaryExpression): FlowNode {
setFlowNodeReferenced(antecedent);
const res: FlowArrayMutation = { flags: FlowFlags.ArrayMutation, antecedent, node };
const res: FlowArrayMutation = flowNodeCreated({ flags: FlowFlags.ArrayMutation, antecedent, node });
return res;
}

Expand Down Expand Up @@ -1080,21 +1085,49 @@ namespace ts {
function bindTryStatement(node: TryStatement): void {
const preFinallyLabel = createBranchLabel();
const preTryFlow = currentFlow;
// TODO: Every statement in try block is potentially an exit point!
const tryPriors: FlowNode[] = [];
const oldFlowNodeCreated = flowNodeCreated;
// We hook the creation of all flow nodes within the `try` scope and store them so we can add _all_ of them
// as possible antecedents of the start of the `catch` or `finally` blocks.
// Don't bother intercepting the call if there's no finally or catch block that needs the information
if (node.catchClause || node.finallyBlock) {
flowNodeCreated = node => (tryPriors.push(node), node);
}
bind(node.tryBlock);
flowNodeCreated = oldFlowNodeCreated;
addAntecedent(preFinallyLabel, currentFlow);

const flowAfterTry = currentFlow;
let flowAfterCatch = unreachableFlow;

if (node.catchClause) {
currentFlow = preTryFlow;
if (tryPriors.length) {
const preCatchFlow = createBranchLabel();
addAntecedent(preCatchFlow, currentFlow);
for (const p of tryPriors) {
addAntecedent(preCatchFlow, p);
}
currentFlow = finishFlowLabel(preCatchFlow);
}

bind(node.catchClause);
addAntecedent(preFinallyLabel, currentFlow);

flowAfterCatch = currentFlow;
}
if (node.finallyBlock) {
// We add the nodes within the `try` block to the `finally`'s antecedents if there's no catch block
// (If there is a `catch` block, it will have all these antecedents instead, and the `finally` will
// have the end of the `try` block and the end of the `catch` block)
if (!node.catchClause) {
if (tryPriors.length) {
for (const p of tryPriors) {
addAntecedent(preFinallyLabel, p);
}
}
}

// in finally flow is combined from pre-try/flow from try/flow from catch
// pre-flow is necessary to make sure that finally is reachable even if finally flows in both try and finally blocks are unreachable

Expand Down Expand Up @@ -1142,7 +1175,7 @@ namespace ts {
}
}
if (!(currentFlow.flags & FlowFlags.Unreachable)) {
const afterFinallyFlow: AfterFinallyFlow = { flags: FlowFlags.AfterFinally, antecedent: currentFlow };
const afterFinallyFlow: AfterFinallyFlow = flowNodeCreated({ flags: FlowFlags.AfterFinally, antecedent: currentFlow });
preFinallyFlow.lock = afterFinallyFlow;
currentFlow = afterFinallyFlow;
}
Expand Down
Loading

0 comments on commit f62e3b0

Please sign in to comment.