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

Target not optional (compiler api) #1758

Closed
ivogabe opened this issue Jan 21, 2015 · 4 comments
Closed

Target not optional (compiler api) #1758

ivogabe opened this issue Jan 21, 2015 · 4 comments

Comments

@ivogabe
Copy link
Contributor

ivogabe commented Jan 21, 2015

The compiler option interface is declared with an optional target property:

    interface CompilerOptions {
        allowNonTsExtensions?: boolean;
        charset?: string;
        codepage?: number;
        declaration?: boolean;
        diagnostics?: boolean;
        emitBOM?: boolean;
        help?: boolean;
        locale?: string;
        mapRoot?: string;
        module?: ModuleKind;
        noEmitOnError?: boolean;
        noErrorTruncation?: boolean;
        noImplicitAny?: boolean;
        noLib?: boolean;
        noLibCheck?: boolean;
        noResolve?: boolean;
        out?: string;
        outDir?: string;
        preserveConstEnums?: boolean;
        removeComments?: boolean;
        sourceMap?: boolean;
        sourceRoot?: string;
        suppressImplicitAnyIndexErrors?: boolean;
        target?: ScriptTarget;
        version?: boolean;
        watch?: boolean;
        [option: string]: string | number | boolean;
    }

But when you provide an empty object {} to the compiler api, certain code won't compile. The last lines of compileNode are:

                if (compilerOptions.target < 2 /* ES6 */) {
                    switch (node.kind) {
                        case 199 /* ShorthandPropertyAssignment */:
                            return emitDownlevelShorthandPropertyAssignment(node);
                        case 125 /* Method */:
                            return emitDownlevelMethod(node);
                    }
                }
                else {
                    ts.Debug.assert(compilerOptions.target >= 2 /* ES6 */, "Invalid ScriptTarget. We should emit as ES6 or above");
                    switch (node.kind) {
                        case 199 /* ShorthandPropertyAssignment */:
                            return emitShorthandPropertyAssignment(node);
                        case 125 /* Method */:
                            return emitMethod(node);
                    }
                }

The Debug.assert will fail, because undefined isn't smaller, equal nor bigger than 2 (ES6). Is this by design, or not? If this is by design, the target property should probably be marked as required.

@mhegazy
Copy link
Contributor

mhegazy commented Jan 21, 2015

Commit : 65452aa should handle the issue.

@ivogabe
Copy link
Contributor Author

ivogabe commented Jan 21, 2015

Thanks, will that fix be released in version 1.4.2?

@mhegazy
Copy link
Contributor

mhegazy commented Jan 21, 2015

no, in release 1.5, release 1.4.2 is just 1.4 in addition to critical bug fixes.

@ivogabe
Copy link
Contributor Author

ivogabe commented Jan 21, 2015

Ok. Just patched it in gulp-typescript, it will set now the target & module by default if they are undefined, so that's working again.

@ivogabe ivogabe closed this as completed Jan 21, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants