Skip to content

resolveJsonModule transpile does not strip trailing commas #24530

@cspotcode

Description

@cspotcode

TypeScript Version: 2.9.1

Search Terms:

JSON
resolveJsonModule
json trailing comma

Code

import * as ts from 'typescript';
console.log(ts.version);
const output = ts.transpileModule(
    `
        {"foo": 123,} // note trailing comma
    `,
    {
        fileName: 'foo.json',
        compilerOptions: {
            resolveJsonModule: true,
            removeComments: true
        },
        reportDiagnostics: true
    }
);
console.dir(output.diagnostics); // no errors
console.dir(output.outputText); // '{ "foo": 123, }\r\n' still has trailing comma

Expected behavior:

Emitted JSON does not have trailing comma: { "foo": 123 }
...or compiler emits a diagnostic to tell me the trailing comma is not allowed in input json.

Actual behavior:

Emitted JSON has trailing comma: { "foo": 123, } and no diagnostics are reported.

Playground Link:

N/A because Playground assumes .ts file extension.

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions