parent
d187de2076
commit
1696da14f2
|
@ -1458,7 +1458,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
const preferNewLine = node.multiLine ? ListFormat.PreferNewLine : ListFormat.None;
|
const preferNewLine = node.multiLine ? ListFormat.PreferNewLine : ListFormat.None;
|
||||||
const allowTrailingComma = currentSourceFile.languageVersion >= ScriptTarget.ES5 ? ListFormat.AllowTrailingComma : ListFormat.None;
|
const allowTrailingComma = currentSourceFile.languageVersion >= ScriptTarget.ES5 && !isJsonSourceFile(currentSourceFile) ? ListFormat.AllowTrailingComma : ListFormat.None;
|
||||||
emitList(node, node.properties, ListFormat.ObjectLiteralExpressionProperties | allowTrailingComma | preferNewLine);
|
emitList(node, node.properties, ListFormat.ObjectLiteralExpressionProperties | allowTrailingComma | preferNewLine);
|
||||||
|
|
||||||
if (indentedFlag) {
|
if (indentedFlag) {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
//// [tests/cases/compiler/requireOfJsonFileWithTraillingComma.ts] ////
|
||||||
|
|
||||||
|
//// [file1.ts]
|
||||||
|
import b1 = require('./b.json');
|
||||||
|
let x = b1.a;
|
||||||
|
import b2 = require('./b.json');
|
||||||
|
if (x) {
|
||||||
|
let b = b2.b;
|
||||||
|
x = (b1.b === b);
|
||||||
|
}
|
||||||
|
|
||||||
|
//// [b.json]
|
||||||
|
{
|
||||||
|
"a": true,
|
||||||
|
"b": "hello",
|
||||||
|
}
|
||||||
|
|
||||||
|
//// [out/b.json]
|
||||||
|
{
|
||||||
|
"a": true,
|
||||||
|
"b": "hello"
|
||||||
|
}
|
||||||
|
//// [out/file1.js]
|
||||||
|
"use strict";
|
||||||
|
exports.__esModule = true;
|
||||||
|
var b1 = require("./b.json");
|
||||||
|
var x = b1.a;
|
||||||
|
var b2 = require("./b.json");
|
||||||
|
if (x) {
|
||||||
|
var b = b2.b;
|
||||||
|
x = (b1.b === b);
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
=== tests/cases/compiler/file1.ts ===
|
||||||
|
import b1 = require('./b.json');
|
||||||
|
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||||
|
|
||||||
|
let x = b1.a;
|
||||||
|
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||||
|
>b1.a : Symbol("a", Decl(b.json, 0, 1))
|
||||||
|
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||||
|
>a : Symbol("a", Decl(b.json, 0, 1))
|
||||||
|
|
||||||
|
import b2 = require('./b.json');
|
||||||
|
>b2 : Symbol(b2, Decl(file1.ts, 1, 13))
|
||||||
|
|
||||||
|
if (x) {
|
||||||
|
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||||
|
|
||||||
|
let b = b2.b;
|
||||||
|
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||||
|
>b2.b : Symbol("b", Decl(b.json, 1, 14))
|
||||||
|
>b2 : Symbol(b2, Decl(file1.ts, 1, 13))
|
||||||
|
>b : Symbol("b", Decl(b.json, 1, 14))
|
||||||
|
|
||||||
|
x = (b1.b === b);
|
||||||
|
>x : Symbol(x, Decl(file1.ts, 1, 3))
|
||||||
|
>b1.b : Symbol("b", Decl(b.json, 1, 14))
|
||||||
|
>b1 : Symbol(b1, Decl(file1.ts, 0, 0))
|
||||||
|
>b : Symbol("b", Decl(b.json, 1, 14))
|
||||||
|
>b : Symbol(b, Decl(file1.ts, 4, 7))
|
||||||
|
}
|
||||||
|
|
||||||
|
=== tests/cases/compiler/b.json ===
|
||||||
|
{
|
||||||
|
"a": true,
|
||||||
|
>"a" : Symbol("a", Decl(b.json, 0, 1))
|
||||||
|
|
||||||
|
"b": "hello",
|
||||||
|
>"b" : Symbol("b", Decl(b.json, 1, 14))
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
=== tests/cases/compiler/file1.ts ===
|
||||||
|
import b1 = require('./b.json');
|
||||||
|
>b1 : { "a": boolean; "b": string; }
|
||||||
|
|
||||||
|
let x = b1.a;
|
||||||
|
>x : boolean
|
||||||
|
>b1.a : boolean
|
||||||
|
>b1 : { "a": boolean; "b": string; }
|
||||||
|
>a : boolean
|
||||||
|
|
||||||
|
import b2 = require('./b.json');
|
||||||
|
>b2 : { "a": boolean; "b": string; }
|
||||||
|
|
||||||
|
if (x) {
|
||||||
|
>x : boolean
|
||||||
|
|
||||||
|
let b = b2.b;
|
||||||
|
>b : string
|
||||||
|
>b2.b : string
|
||||||
|
>b2 : { "a": boolean; "b": string; }
|
||||||
|
>b : string
|
||||||
|
|
||||||
|
x = (b1.b === b);
|
||||||
|
>x = (b1.b === b) : boolean
|
||||||
|
>x : boolean
|
||||||
|
>(b1.b === b) : boolean
|
||||||
|
>b1.b === b : boolean
|
||||||
|
>b1.b : string
|
||||||
|
>b1 : { "a": boolean; "b": string; }
|
||||||
|
>b : string
|
||||||
|
>b : string
|
||||||
|
}
|
||||||
|
|
||||||
|
=== tests/cases/compiler/b.json ===
|
||||||
|
{
|
||||||
|
>{ "a": true, "b": "hello",} : { "a": boolean; "b": string; }
|
||||||
|
|
||||||
|
"a": true,
|
||||||
|
>"a" : boolean
|
||||||
|
>true : true
|
||||||
|
|
||||||
|
"b": "hello",
|
||||||
|
>"b" : string
|
||||||
|
>"hello" : "hello"
|
||||||
|
}
|
20
tests/cases/compiler/requireOfJsonFileWithTraillingComma.ts
Normal file
20
tests/cases/compiler/requireOfJsonFileWithTraillingComma.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// @module: commonjs
|
||||||
|
// @outdir: out/
|
||||||
|
// @allowJs: true
|
||||||
|
// @fullEmitPaths: true
|
||||||
|
// @resolveJsonModule: true
|
||||||
|
|
||||||
|
// @Filename: file1.ts
|
||||||
|
import b1 = require('./b.json');
|
||||||
|
let x = b1.a;
|
||||||
|
import b2 = require('./b.json');
|
||||||
|
if (x) {
|
||||||
|
let b = b2.b;
|
||||||
|
x = (b1.b === b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Filename: b.json
|
||||||
|
{
|
||||||
|
"a": true,
|
||||||
|
"b": "hello",
|
||||||
|
}
|
Loading…
Reference in a new issue