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

program.emit() skips JavaScript modules #7363

Closed
s-panferov opened this issue Mar 3, 2016 · 4 comments
Closed

program.emit() skips JavaScript modules #7363

s-panferov opened this issue Mar 3, 2016 · 4 comments
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code

Comments

@s-panferov
Copy link

TypeScript Version:

nightly@1.9.0-dev.20160303

Problem

TypeScript doesn't emit JS modules when using compiler API (allowJs is enabled):

Code

function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) {
    outputFiles.push({
        sourceName: fileName,
        name: fileName,
        writeByteOrderMark: writeByteOrderMark,
        text: data
    });
}

let source = program.getSourceFile(fileName);

/* source is defined and it is a valid js module
   see getSourceFiles() output below
*/

let emitResult = program.emit(source, writeFile);

/* { emitSkipped: true, diagnostics: [], sourceMaps: [] } */

JS module source

/**
 * Sum
 * @param  {number} a
 * @param  {number} b
 * @return {number}
 */
function sum(a, b) {
    return a + b;
}

class Test {
    mod() {

    }
}

sum('test', 1);

getSourceFiles()

console.log(this.program.getSourceFiles());

Output

[ SourceFileObject {
    kind: 252,
    pos: 0,
    end: 180,
    flags: 134217728,
    parent: undefined,
    text: '/**\n * Sum\n * @param  {number} a\n * @param  {number} b\n * @return {number}\n */\nfunction sum(a, b) {\n    return a + b;\n}\n\nclass Test {\n    mod() {\n        \n    }\n}\n\nsum(\'test\', 1);\n',
    bindDiagnostics: [],
    languageVersion: 1,
    fileName: '/Users/panferov/Workspace/my/awesome-typescript-loader/src/test/fixtures/salsa/index.js',
    languageVariant: 1,
    isDeclarationFile: false,
    scriptKind: 1,
    referencedFiles: [],
    amdDependencies: [],
    moduleName: undefined,
    statements: [ [Object], [Object], [Object], pos: 0, end: 179 ],
    endOfFileToken:
     NodeObject {
       kind: 1,
       pos: 179,
       end: 180,
       flags: 134217728,
       parent: [Circular] },
    externalModuleIndicator: undefined,
    nodeCount: 42,
    identifierCount: 8,
    identifiers: { sum: 'sum', a: 'a', b: 'b', Test: 'Test', mod: 'mod' },
    parseDiagnostics: [],
    version: '0',
    scriptSnapshot:
     StringScriptSnapshot {
       text: '/**\n * Sum\n * @param  {number} a\n * @param  {number} b\n * @return {number}\n */\nfunction sum(a, b) {\n    return a + b;\n}\n\nclass Test {\n    mod() {\n        \n    }\n}\n\nsum(\'test\', 1);\n' },
    path: '/users/panferov/workspace/my/awesome-typescript-loader/src/test/fixtures/salsa/index.js',
    imports: [],
    moduleAugmentations: [],
    resolvedModules: undefined,
    locals: { sum: [Object], Test: [Object] },
    nextContainer:
     NodeObject {
       kind: 217,
       pos: 0,
       end: 119,
       flags: 134217728,
       parent: [Circular],
       decorators: undefined,
       asteriskToken: undefined,
       name: [Object],
       typeParameters: undefined,
       parameters: [Object],
       body: [Object],
       jsDocComment: [Object],
       symbol: [Object],
       locals: [Object],
       nextContainer: [Object] },
    symbolCount: 6,
    classifiableNames: { Test: 'Test' } } ]

Expected behavior:

emitResult.emitSkipped == false

Actual behavior:

emitResult.emitSkipped == true

@frankwallis
Copy link
Contributor

Possibly you need to use the new compiler option suppressOutputPathCheck see #6766

@vladima
Copy link
Contributor

vladima commented Mar 3, 2016

do you have any emit blocking diagnostics? what is the result of program.getOptionsDiagnostics()

@mhegazy
Copy link
Contributor

mhegazy commented Mar 3, 2016

the compiler will not overwrite an input file. so if the output has the same path as an input file, it will not be emitted. use outDir instead.

@mhegazy mhegazy added Question An issue which isn't directly actionable in code API Relates to the public API for TypeScript labels Mar 3, 2016
@s-panferov
Copy link
Author

suppressOutputPathCheck works, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants