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

Fix parenthesization rules for yield #37849

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/compiler/factoryPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1555,9 +1555,11 @@ namespace ts {
export function createYield(expression?: Expression): YieldExpression;
export function createYield(asteriskToken: AsteriskToken | undefined, expression: Expression): YieldExpression;
export function createYield(asteriskTokenOrExpression?: AsteriskToken | undefined | Expression, expression?: Expression) {
const asteriskToken = asteriskTokenOrExpression && asteriskTokenOrExpression.kind === SyntaxKind.AsteriskToken ? <AsteriskToken>asteriskTokenOrExpression : undefined;
expression = asteriskTokenOrExpression && asteriskTokenOrExpression.kind !== SyntaxKind.AsteriskToken ? asteriskTokenOrExpression : expression;
const node = <YieldExpression>createSynthesizedNode(SyntaxKind.YieldExpression);
node.asteriskToken = asteriskTokenOrExpression && asteriskTokenOrExpression.kind === SyntaxKind.AsteriskToken ? <AsteriskToken>asteriskTokenOrExpression : undefined;
node.expression = asteriskTokenOrExpression && asteriskTokenOrExpression.kind !== SyntaxKind.AsteriskToken ? asteriskTokenOrExpression : expression;
node.asteriskToken = asteriskToken;
node.expression = expression && parenthesizeExpressionForList(expression);
return node;
}

Expand Down
59 changes: 59 additions & 0 deletions tests/baselines/reference/importCallExpressionInUMD5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//// [tests/cases/conformance/dynamicImport/importCallExpressionInUMD5.ts] ////

//// [0.ts]
export function foo() { return "foo"; }

//// [1.ts]
// https://github.com/microsoft/TypeScript/issues/36780
async function func() {
const packageName = '.';
const packageJson = await import(packageName + '/package.json');
}


//// [0.js]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = void 0;
function foo() { return "foo"; }
exports.foo = foo;
});
//// [1.js]
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
// https://github.com/microsoft/TypeScript/issues/36780
function func() {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const packageName = '.';
const packageJson = yield (_a = packageName + '/package.json', __syncRequire ? Promise.resolve().then(() => require(_a)) : new Promise((resolve_1, reject_1) => { require([_a], resolve_1, reject_1); }));
});
}
});
17 changes: 17 additions & 0 deletions tests/baselines/reference/importCallExpressionInUMD5.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/conformance/dynamicImport/0.ts ===
export function foo() { return "foo"; }
>foo : Symbol(foo, Decl(0.ts, 0, 0))

=== tests/cases/conformance/dynamicImport/1.ts ===
// https://github.com/microsoft/TypeScript/issues/36780
async function func() {
>func : Symbol(func, Decl(1.ts, 0, 0))

const packageName = '.';
>packageName : Symbol(packageName, Decl(1.ts, 2, 9))

const packageJson = await import(packageName + '/package.json');
>packageJson : Symbol(packageJson, Decl(1.ts, 3, 9))
>packageName : Symbol(packageName, Decl(1.ts, 2, 9))
}

23 changes: 23 additions & 0 deletions tests/baselines/reference/importCallExpressionInUMD5.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
=== tests/cases/conformance/dynamicImport/0.ts ===
export function foo() { return "foo"; }
>foo : () => string
>"foo" : "foo"

=== tests/cases/conformance/dynamicImport/1.ts ===
// https://github.com/microsoft/TypeScript/issues/36780
async function func() {
>func : () => Promise<void>

const packageName = '.';
>packageName : "."
>'.' : "."

const packageJson = await import(packageName + '/package.json');
>packageJson : any
>await import(packageName + '/package.json') : any
>import(packageName + '/package.json') : Promise<any>
>packageName + '/package.json' : string
>packageName : "."
>'/package.json' : "/package.json"
}

2 changes: 1 addition & 1 deletion tests/baselines/reference/importCallExpressionNestedUMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
function foo() {
return __awaiter(this, void 0, void 0, function* () {
var _a;
return yield _a = (yield __syncRequire ? Promise.resolve().then(() => require("./foo")) : new Promise((resolve_1, reject_1) => { require(["./foo"], resolve_1, reject_1); })).default, __syncRequire ? Promise.resolve().then(() => require(_a)) : new Promise((resolve_2, reject_2) => { require([_a], resolve_2, reject_2); });
return yield (_a = (yield __syncRequire ? Promise.resolve().then(() => require("./foo")) : new Promise((resolve_1, reject_1) => { require(["./foo"], resolve_1, reject_1); })).default, __syncRequire ? Promise.resolve().then(() => require(_a)) : new Promise((resolve_2, reject_2) => { require([_a], resolve_2, reject_2); }));
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @module: umd
// @target: es2015
// @filename: 0.ts
export function foo() { return "foo"; }

// @filename: 1.ts

// https://github.com/microsoft/TypeScript/issues/36780
async function func() {
const packageName = '.';
const packageJson = await import(packageName + '/package.json');
}