Skip to content

target es2015 + module system + import used in object shorthand -> incorrect output #21057

@mpal9000

Description

@mpal9000

TypeScript Version: 2.7.0-dev.20180107

Code

// tsconfig.json
{
  "compilerOptions": {
    "lib": ["es2015"],
    "module": "system",
    "outDir": "./dist",
    "target": "es2015"
  },
  "include": ["./src/**/*"]
}
// index.ts
import {x} from './x.js'

const x2 = {x} // `x` undefined
console.log({x2})

const x3 = x
console.log({x3})

// same with default export/import
// x.ts
export const x = 'X'
// index.js
System.register(["./x.js"], function (exports_1, context_1) {
    "use strict";
    var __moduleName = context_1 && context_1.id;
    var x_js_1, x2, x3;
    return {
        setters: [
            function (x_js_1_1) {
                x_js_1 = x_js_1_1;
            }
        ],
        execute: function () {
            x2 = { x }; // `x` undefined
            console.log({ x2 });
            x3 = x_js_1.x;
            console.log({ x3 });
            // same with default export/import
        }
    };
});

Expected behavior:
Imported values can be used with "object shorthand" es2015 syntax, when using the "system" module format.

Actual behavior:
In index.js, {x} object shorthand is correctly left untranspiled, but x is undefined.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions