Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Functions #1781

Closed
wants to merge 112 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
0a889c6
Added 'async' and 'await' keywords to parser
rbuckton Nov 22, 2014
def7460
Adding some tests for 'async'
rbuckton Nov 22, 2014
96c44b3
Added async/await to checker
rbuckton Nov 22, 2014
d51b8bd
Added factory, rewriter, and emit for generated nodes.
rbuckton Nov 25, 2014
bf28560
Renamed BodyGenerator to CodeGenerator, removed offsets from Exceptio…
rbuckton Nov 25, 2014
a60cd3a
Merge 'master' to 'prototypeAsync'
rbuckton Nov 25, 2014
1f190ba
- cleaned up rewriter
rbuckton Nov 26, 2014
f8bbe78
Fixed whitespace in Jakefile
rbuckton Nov 26, 2014
ead809b
merged 'master' to 'prototypeAsync'
rbuckton Nov 26, 2014
4fad214
Fix for breaks following merge
rbuckton Nov 26, 2014
7c8fd3d
Fix for labels, emitGeneratedNode indentation, and bugs in emit outpu…
rbuckton Nov 26, 2014
4dac41a
rewrite of function parameters with initializers and fixed capturing …
rbuckton Nov 26, 2014
389962b
Merge branch 'master' into prototypeAsync
rbuckton Nov 26, 2014
d2bdf6e
Added additional diagnostics around __awaiter and __generator and cha…
rbuckton Nov 27, 2014
a8c8918
Tests for async/await, plus bugfixes
rbuckton Dec 2, 2014
dc2e6bd
Added updated reference files for test cases
rbuckton Dec 2, 2014
938e0cd
More tests, cleanup for code generator, switched to mechanism for cre…
rbuckton Dec 3, 2014
868cf6d
fix for type check of reserved identifiers in compiler.
rbuckton Dec 5, 2014
6c3eace
Refactored generated locals to a separate object, some work to preser…
rbuckton Dec 6, 2014
1488944
Fixed comment emit for nodes inside of a generated node.
rbuckton Dec 6, 2014
cb4bc4f
More cleanup for comment preservation
rbuckton Dec 6, 2014
faaf778
Updated tests, fix for variable statement emit
rbuckton Dec 6, 2014
cfdb9ac
centralized getPromiseConstructor to checker.ts
rbuckton Dec 7, 2014
4ade643
Updated sourcemap output for generated nodes
rbuckton Dec 10, 2014
155b9a5
cleaned up generated code
rbuckton Dec 10, 2014
38d2218
Updated test baselines, fixed error in for..in rewrite
rbuckton Dec 10, 2014
1de7be3
First pass at merge from master
rbuckton Dec 13, 2014
18c2d50
Fixed diagnostic message numbering, updated some baselines
rbuckton Dec 13, 2014
26c6b80
Updated baselines from master
rbuckton Dec 13, 2014
a097c2b
Updated baselines
rbuckton Dec 14, 2014
b4f21c4
Test fixes, Added AsyncParameter parser context, updated baselines
rbuckton Dec 16, 2014
be9653b
Merged generated locals between async/await and destructuring
rbuckton Dec 16, 2014
f330910
Added emitYieldExpression to emitter to support async/await in ES6 mode.
rbuckton Dec 21, 2014
de210f0
Fixed undefined reference check in checkAwaitableReturnType
rbuckton Dec 21, 2014
701b19d
Simplified creation of IPromise/IPromiseConstructor types in checker
rbuckton Dec 21, 2014
0b0703b
Allow return type inference for async functions when Promise<T> is in…
rbuckton Jan 5, 2015
28799ab
Merge branch 'master' into prototypeAsync
rbuckton Jan 6, 2015
8f3dd8c
Fixed nodeIsMissing test to fix emit output for generated functions
rbuckton Jan 6, 2015
c533514
Centralized visitor and some cleanup.
rbuckton Jan 7, 2015
a0adf6f
Fixed label numbering in generator
rbuckton Jan 7, 2015
ae6a2af
Fix for bug in createTypeChecker
rbuckton Jan 7, 2015
ecfbd97
Updated test baselines for async functions
rbuckton Jan 10, 2015
dc2a8d0
Fixed label numbering
rbuckton Jan 10, 2015
7b39c80
Fixed var declarations and marked some errors as early errors.
rbuckton Jan 11, 2015
bad02ab
Cleaned up generated output, reduced emit of unnecessary statements
rbuckton Jan 11, 2015
aba2aed
Fixed import reference for promise constructor across multiple files
rbuckton Jan 12, 2015
ecb8f9e
Fixed indentation for __generator
rbuckton Jan 13, 2015
98378d1
Fixed return for factory.updateThrowStatement
rbuckton Jan 13, 2015
0221763
Updated __generator emit to match spec proposal
rbuckton Jan 13, 2015
53c5d26
Removed three unnecessary array allocations in __generator and update…
rbuckton Jan 13, 2015
6185092
Add support for parameter and variable destructuring in async functions
rbuckton Jan 14, 2015
c88dce4
Fixed order of operations during emit for await in a BindingPattern i…
rbuckton Jan 15, 2015
e4a808c
Cleaned up destructuring for BindingElement and added rewrite for des…
rbuckton Jan 15, 2015
a1b29e5
Removed unused function
rbuckton Jan 15, 2015
a62ea04
Rewrite for SpreadElementExpression
rbuckton Jan 15, 2015
b042658
Fixed bug in spread element rewrite, updated test baselines
rbuckton Jan 15, 2015
69c16b4
Added script to generate most of Factory and Visitor
rbuckton Jan 17, 2015
bd98edb
Renamed syntax.json
rbuckton Jan 19, 2015
b4d5e0d
Migrate emitter to use rewrite methods for destructuring/spread element
rbuckton Jan 20, 2015
1aafc40
Removed emitDestructuring function
rbuckton Jan 20, 2015
38a95f1
Fixed emit for parenthesized expressions, fixed rewrite for destructu…
rbuckton Jan 20, 2015
3e30ed1
Updated baseline for destructuring
rbuckton Jan 20, 2015
70023dc
Added test cases for es6 emit
rbuckton Jan 21, 2015
c21918c
Additional typecheck for yield
rbuckton Jan 21, 2015
20aab8e
Fixed bug for "yield*" in __generator
rbuckton Jan 21, 2015
0a7270e
Add visitor handler for Identifier
rbuckton Jan 21, 2015
4101450
Fixed rewrite for labeled statement, for in, yield*, and variable dec…
rbuckton Jan 21, 2015
efc2809
Added new tests for es6 and binding elements in es5/3
rbuckton Jan 21, 2015
f100bfc
Added capture for lexical arguments in async function
rbuckton Jan 21, 2015
8a90e27
Fixed break/continue in labeled loop, switched to literal numbers for…
rbuckton Jan 22, 2015
75e1de6
Updated baselines for async tests
rbuckton Jan 22, 2015
5b005f6
Merge branch 'master' into prototypeAsync
rbuckton Jan 22, 2015
20a9a6c
Merge branch 'prototypeAsync' from rbuckton/TypeScript into prototype…
rbuckton Jan 22, 2015
cefeaf0
Cleaned up whitespace
rbuckton Jan 22, 2015
1d1f784
Fix when global IPromise and IPromiseConstructor types are not found.
rbuckton Jan 22, 2015
525b7d2
Added support for `await` in `with`
rbuckton Jan 22, 2015
fa1f495
Simplified visitor implementation
rbuckton Jan 24, 2015
7491a72
Functional style for generated locals
rbuckton Jan 24, 2015
a46fa3c
Refactored rewriter and visitor to functional style, updated test bas…
rbuckton Jan 29, 2015
8d60e54
Refactor code generation and rewriters to remove closures
rbuckton Jan 30, 2015
276ce4f
Using generic error message for checkAsyncModifier
rbuckton Jan 30, 2015
1aca763
factory generator cleanup
rbuckton Jan 30, 2015
e5a5886
more factory generator cleanup
rbuckton Jan 30, 2015
b5e1efc
more factory generator cleanup and updated baselines for diagnostic m…
rbuckton Jan 30, 2015
d8b2373
Fixed generics on IPromiseConstructor, fixed type check and errors fo…
rbuckton Jan 31, 2015
d059142
Clarified error message for promise constructor collision
rbuckton Jan 31, 2015
95de399
Fixed issue with while/do loop in try/catch, simplified and updated _…
rbuckton Feb 2, 2015
635edca
Updated const numbering for endfinally, downlevel async behind a flag…
rbuckton Feb 2, 2015
0450937
Updated tslib.js to UMD, added tslib.d.ts
rbuckton Feb 3, 2015
4c855df
switched from compilerOptions.target to languageVersion
rbuckton Feb 3, 2015
04b19a0
Refactor common patterns around GeneratorParameter and AsyncParameter
rbuckton Feb 4, 2015
5340f0c
emit 'await' expression as fallback when there are checker errors.
rbuckton Feb 4, 2015
4ac9c35
Added factory, generator, and rewriter to tsconfig.json
rbuckton Feb 4, 2015
2b14c43
Update baselines from parser changes.
rbuckton Feb 4, 2015
195c64e
Further restrictions to disallow async modifier in an accessor
rbuckton Feb 4, 2015
0560e77
Updated baselines for parser changes.
rbuckton Feb 4, 2015
866fba7
Relaxed parsing restriction for 'await' keyword to align with treatme…
rbuckton Feb 4, 2015
86021eb
More consistent handling of ParserContextFlags for Parameters, Bindin…
rbuckton Feb 4, 2015
2e4a614
conformance tests for await in binding element and spread element
rbuckton Feb 4, 2015
22eda41
Fixed await in spread element, added conformance tests
rbuckton Feb 4, 2015
5a34605
Update baselines for spread element, minor revision to rewriteCallExp…
rbuckton Feb 4, 2015
aaa122b
Changed visitVariableDeclaration to emit an identifier with no source…
rbuckton Feb 4, 2015
c8ec582
Merge branch 'master' to prototypeAsync
rbuckton Feb 5, 2015
dd6bc44
Added missing dependency to Jakefile for tslib
rbuckton Feb 10, 2015
e1bc0bd
Added error when unable to infer a return type as a Promise for an as…
rbuckton Feb 12, 2015
7f6ea09
Merge branch 'prototypeAsync' of https://github.com/Microsoft/TypeScr…
rbuckton Feb 12, 2015
763edc6
A number of updates based on CR feedback
rbuckton Feb 14, 2015
ab3f342
Merge branch 'master' into prototypeAsync
rbuckton Feb 14, 2015
aece9ae
Fixed error in colorization.ts in unit tests after recent change to s…
rbuckton Feb 14, 2015
4c132c9
Fixes for PR comments and updated baselines.
rbuckton Feb 26, 2015
60a0a49
Various updates from PR feedback.
rbuckton Feb 27, 2015
d57fe72
Updated LKG
rbuckton May 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ tests/services/baselines/prototyping/local/*
tests/services/browser/typescriptServices.js
scripts/processDiagnosticMessages.d.ts
scripts/processDiagnosticMessages.js
scripts/processDiagnosticMessages.js.map
scripts/importDefinitelyTypedTests.js
scripts/processFactory.d.ts
scripts/processFactory.js
scripts/processFactory.js.map
src/harness/*.js
rwc-report.html
*.swp
Expand Down
52 changes: 47 additions & 5 deletions Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ var compilerSources = [
"utilities.ts",
"binder.ts",
"checker.ts",
"factory.ts",
"generator.ts",
"rewriter.ts",
"emitter.ts",
"program.ts",
"commandLineParser.ts",
"tsc.ts",
"diagnosticInformationMap.generated.ts"
"diagnosticInformationMap.generated.ts",
"factory.generated.ts"
].map(function (f) {
return path.join(compilerDirectory, f);
});
Expand All @@ -56,10 +60,14 @@ var servicesSources = [
"utilities.ts",
"binder.ts",
"checker.ts",
"factory.ts",
"generator.ts",
"rewriter.ts",
"emitter.ts",
"program.ts",
"commandLineParser.ts",
"diagnosticInformationMap.generated.ts"
"diagnosticInformationMap.generated.ts",
"factory.generated.ts"
].map(function (f) {
return path.join(compilerDirectory, f);
}).concat([
Expand Down Expand Up @@ -140,6 +148,7 @@ var librarySourceMap = [
{ target: "lib.d.ts", sources: ["core.d.ts", "extensions.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], },
{ target: "lib.core.es6.d.ts", sources: ["core.d.ts", "es6.d.ts"]},
{ target: "lib.es6.d.ts", sources: ["core.d.ts", "es6.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"]},
{ target: "tslib.d.ts", sources: ["tslib.d.ts"]}
];

var libraryTargets = librarySourceMap.map(function (f) {
Expand Down Expand Up @@ -280,10 +289,43 @@ for (var i in libraryTargets) {
})(i);
}

// tslib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's tslib?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An experimental feature we are adding to support async functions in ES5 and earlier. Instead of emitting the __extends, __awaiter, and __generator functions directly in the output file, the developer can instead include a 'tslib.js' file that contains those functions.

tslib.js uses a UMD (Universal Module Dependency) -like approach that makes those functions available on the global when loaded via <script>, or as exported functions when loaded either with CommonJS or AMD. In addition, when importing tslib in Common JS or AMD, you can choose to call a special install exported function that installs the helper methods on the global object.

This is an advanced feature and currently experiemental. If a developer choses to use tslib.js, they may pass the --noHelpers (experimental) command line option to tsc and it will not emit the helper methods to any file.

For example:

import { __extends, __awaiter, __generator } from 'tslib';
class B extends A {
}

Or:

import { install } from 'tslib';
install();

class B extends A {
}

var tslibSource = path.join(libraryDirectory, "tslib.js");
var tslibTarget = path.join(builtLocalDirectory, "tslib.js");
file(tslibTarget, [builtLocalDirectory, copyright, tslibSource], function() {
concatenateFiles(tslibTarget, [copyright, tslibSource]);
})

// Lib target to build the library files
desc("Builds the library targets");
task("lib", libraryTargets);
task("lib", [tslibTarget].concat(libraryTargets));

// Generate factory
var processFactoryJs = path.join(scriptsDirectory, "processFactory.js");
var processFactoryTs = path.join(scriptsDirectory, "processFactory.ts");
var factoryJson = path.join(compilerDirectory, "factory.json");
var factoryGeneratedTs = path.join(compilerDirectory, "factory.generated.ts");
file(processFactoryTs);
compileFile(processFactoryJs, [processFactoryTs], [processFactoryTs], [], /*useBuiltCompile*/ false);
file(factoryGeneratedTs, [processFactoryJs, factoryJson], function() {
var cmd = host + " " + processFactoryJs + " " + factoryJson;
console.log(cmd);
var ex = jake.createExec([cmd]);
// Add listeners for output and error
ex.addListener("stdout", function(output) {
process.stdout.write(output);
});
ex.addListener("stderr", function(error) {
process.stderr.write(error);
});
ex.addListener("cmdEnd", function() {
complete();
});
ex.run();
}, { async: true });

desc("Generates the node factory and visitor in TypeScript based on an input JSON file");
task("generate-factory", [factoryGeneratedTs]);

// Generate diagnostics
var processDiagnosticMessagesJs = path.join(scriptsDirectory, "processDiagnosticMessages.js");
Expand All @@ -302,7 +344,7 @@ compileFile(processDiagnosticMessagesJs,

// The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task
file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], function () {
var cmd = "node " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson;
var cmd = host + " " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson;
console.log(cmd);
var ex = jake.createExec([cmd]);
// Add listeners for output and error
Expand Down Expand Up @@ -509,7 +551,7 @@ function cleanTestDirs() {
}

jake.mkdirP(localRwcBaseline);
jake.mkdirP(localTest262Baseline);
jake.mkdirP(localTest262Baseline);
jake.mkdirP(localBaseline);
}

Expand Down
10 changes: 9 additions & 1 deletion bin/lib.core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ interface Function {
}

interface FunctionConstructor {
/**
/**
* Creates a new function.
* @param args A list of arguments the function accepts.
*/
Expand Down Expand Up @@ -1164,3 +1164,11 @@ interface ArrayConstructor {
}

declare var Array: ArrayConstructor;

interface IPromise<T> {
then<TResult>(onfulfilled: (value: T) => TResult | IPromise<TResult>, onrejected: (reason: any) => TResult | IPromise<TResult>): IPromise<TResult>;
}

interface IPromiseConstructor {
new <T>(init: (resolve: (value: T | IPromise<T>) => void, reject: (reason: any) => void) => void): IPromise<T>;
}
10 changes: 9 additions & 1 deletion bin/lib.core.es6.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ interface Function {
}

interface FunctionConstructor {
/**
/**
* Creates a new function.
* @param args A list of arguments the function accepts.
*/
Expand Down Expand Up @@ -1164,6 +1164,14 @@ interface ArrayConstructor {
}

declare var Array: ArrayConstructor;

interface IPromise<T> {
then<TResult>(onfulfilled: (value: T) => TResult | IPromise<TResult>, onrejected: (reason: any) => TResult | IPromise<TResult>): IPromise<TResult>;
}

interface IPromiseConstructor {
new <T>(init: (resolve: (value: T | IPromise<T>) => void, reject: (reason: any) => void) => void): IPromise<T>;
}
declare type PropertyKey = string | number | Symbol;

interface Symbol {
Expand Down
10 changes: 9 additions & 1 deletion bin/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ interface Function {
}

interface FunctionConstructor {
/**
/**
* Creates a new function.
* @param args A list of arguments the function accepts.
*/
Expand Down Expand Up @@ -1165,6 +1165,14 @@ interface ArrayConstructor {

declare var Array: ArrayConstructor;

interface IPromise<T> {
then<TResult>(onfulfilled: (value: T) => TResult | IPromise<TResult>, onrejected: (reason: any) => TResult | IPromise<TResult>): IPromise<TResult>;
}

interface IPromiseConstructor {
new <T>(init: (resolve: (value: T | IPromise<T>) => void, reject: (reason: any) => void) => void): IPromise<T>;
}

/////////////////////////////
/// IE10 ECMAScript Extensions
/////////////////////////////
Expand Down
10 changes: 9 additions & 1 deletion bin/lib.es6.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ interface Function {
}

interface FunctionConstructor {
/**
/**
* Creates a new function.
* @param args A list of arguments the function accepts.
*/
Expand Down Expand Up @@ -1164,6 +1164,14 @@ interface ArrayConstructor {
}

declare var Array: ArrayConstructor;

interface IPromise<T> {
then<TResult>(onfulfilled: (value: T) => TResult | IPromise<TResult>, onrejected: (reason: any) => TResult | IPromise<TResult>): IPromise<TResult>;
}

interface IPromiseConstructor {
new <T>(init: (resolve: (value: T | IPromise<T>) => void, reject: (reason: any) => void) => void): IPromise<T>;
}
declare type PropertyKey = string | number | Symbol;

interface Symbol {
Expand Down
Loading