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

SyntaxError: Missing initializer in const declaration with await on UMD #36780

Closed
filipesilva opened this issue Feb 13, 2020 · 1 comment · Fixed by #37849
Closed

SyntaxError: Missing initializer in const declaration with await on UMD #36780

filipesilva opened this issue Feb 13, 2020 · 1 comment · Fixed by #37849
Assignees
Labels
Bug A bug in TypeScript Domain: Transforms Relates to the public transform API

Comments

@filipesilva
Copy link
Contributor

TypeScript Version: 3.7.5

Search Terms:
SyntaxError: Missing initializer in const declaration
yield generator argument syntaxerror

Code

export async function func() {
  const packageName = '.';
  const packageJson = await import(packageName + '/package.json');
}
{
  "compilerOptions": {
    "module": "UMD",
    "target": "es2015",
  },
  "files": [
    "test.ts"
  ]
}

Expected behavior:
TS outputs valid syntax.

Actual behavior:
TS outputs invalid syntax.

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";
    Object.defineProperty(exports, "__esModule", { value: true });
    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); });
        });
    }
    exports.func = func;
});

When executed on node, I get following error:

kamik@RED-X1C6 MINGW64 /d/sandbox/random (master)
$ node test.js 
D:\sandbox\random\test.js:26
            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); });
                                                                          ^^^^^^^^^^^^^

SyntaxError: Missing initializer in const declaration
←[90m    at Module._compile (internal/modules/cjs/loader.js:718:23)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:641:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:556:12)←[39m
←[90m    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)←[39m
←[90m    at internal/main/run_main_module.js:17:11←[39m
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Transforms Relates to the public transform API labels Feb 13, 2020
@DanielRosenwasser
Copy link
Member

Sounds like we need to do more work to ensure an expression is parenthesized when emitting a comma expression

@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.9.0 milestone Feb 13, 2020
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Mar 5, 2020
The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Mar 19, 2020
The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Mar 19, 2020
…UMDs

The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Mar 24, 2020
…UMDs

The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Mar 24, 2020
…UMDs

The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Mar 26, 2020
…UMDs

The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Mar 31, 2020
…UMDs

The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Mar 31, 2020
…UMDs

The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Apr 7, 2020
…UMDs

The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
mgechev pushed a commit to angular/angular-cli that referenced this issue Apr 7, 2020
…UMDs

The TS bug is microsoft/TypeScript#36780.

The workaround is needed because `ts_library` emits UMDs currently. This will change with bazelbuild/rules_typescript#492 and bazel-contrib/rules_nodejs#1687.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Transforms Relates to the public transform API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants