Skip to content

transpilation doesn't handle multiple prologue directives #24689

@ajafff

Description

@ajafff

TypeScript Version: 3.0.0-dev.20180605

Search Terms:

Code

// this is obviously a bogus function just to have a minimal repro
function test(p: any) {
    'use strong';
    'use strict';
    p = {prop: p} = p;
}

Expected behavior:

function test(p) {
    'use strong';
    'use strict';
    var _a;
    p = (_a = p, p = _a.prop, _a);
}

Actual behavior:

function test(p) {
    'use strong';
    var _a;
    'use strict';
    p = (_a = p, p = _a.prop, _a);
}

The transpiled code has different semantics, because 'use strict' is no longer treated as directive.

I don't know if this also affects other transformers that add statements.

Note that TypeScript correctly detects the 'use strict' directive and would correctly complain about octal literals.

Playground Link:

Related Issues:
#24582
#24386 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions