Skip to content

Commit bd515b9

Browse files
committed
Fix json source file export modifier under new output
1 parent 67b1809 commit bd515b9

File tree

7 files changed

+384
-7
lines changed

7 files changed

+384
-7
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4970,7 +4970,7 @@ namespace ts {
49704970
function addResult(node: Statement, additionalModifierFlags: ModifierFlags) {
49714971
let newModifierFlags: ModifierFlags = ModifierFlags.None;
49724972
if (((additionalModifierFlags & ModifierFlags.Export) && enclosingDeclaration &&
4973-
((isSourceFile(enclosingDeclaration) && isExternalOrCommonJsModule(enclosingDeclaration)) ||
4973+
((isSourceFile(enclosingDeclaration) && (isExternalOrCommonJsModule(enclosingDeclaration) || isJsonSourceFile(enclosingDeclaration))) ||
49744974
(isAmbientModule(enclosingDeclaration) && !isGlobalScopeAugmentation(enclosingDeclaration)))) &&
49754975
(isEnumDeclaration(node) || isVariableStatement(node) || isFunctionDeclaration(node) || isClassDeclaration(node) || (isModuleDeclaration(node) && !isExternalModuleAugmentation(node) && !isGlobalScopeAugmentation(node)) || isInterfaceDeclaration(node) || isTypeDeclaration(node))
49764976
) {

tests/baselines/reference/jsDeclarationsJson.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ module.exports = j;
2626

2727

2828
//// [obj.d.ts]
29-
declare const x: number;
30-
declare const y: number;
31-
declare namespace obj {
32-
const items: ({
29+
export declare const x: number;
30+
export declare const y: number;
31+
export declare namespace obj {
32+
export const items: ({
3333
"x": number;
3434
"y"?: undefined;
3535
"err"?: undefined;
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsPackageJson.ts] ////
2+
3+
//// [index.js]
4+
const j = require("./package.json");
5+
module.exports = j;
6+
//// [package.json]
7+
{
8+
"name": "pkg",
9+
"version": "0.1.0",
10+
"description": "A package",
11+
"main": "./dist/index.js",
12+
"bin": {
13+
"cli": "./bin/cli.js",
14+
},
15+
"engines": {
16+
"node": ">=0"
17+
},
18+
"scripts": {
19+
"scriptname": "run && run again",
20+
},
21+
"devDependencies": {
22+
"@ns/dep": "0.1.2",
23+
},
24+
"dependencies": {
25+
"dep": "1.2.3",
26+
},
27+
"repository": "microsoft/TypeScript",
28+
"keywords": [
29+
"kw"
30+
],
31+
"author": "Auth",
32+
"license": "See Licensce",
33+
"homepage": "https://site",
34+
"config": {
35+
"o": ["a"]
36+
}
37+
}
38+
39+
40+
//// [package.json]
41+
{
42+
"name": "pkg",
43+
"version": "0.1.0",
44+
"description": "A package",
45+
"main": "./dist/index.js",
46+
"bin": {
47+
"cli": "./bin/cli.js"
48+
},
49+
"engines": {
50+
"node": ">=0"
51+
},
52+
"scripts": {
53+
"scriptname": "run && run again"
54+
},
55+
"devDependencies": {
56+
"@ns/dep": "0.1.2"
57+
},
58+
"dependencies": {
59+
"dep": "1.2.3"
60+
},
61+
"repository": "microsoft/TypeScript",
62+
"keywords": [
63+
"kw"
64+
],
65+
"author": "Auth",
66+
"license": "See Licensce",
67+
"homepage": "https://site",
68+
"config": {
69+
"o": ["a"]
70+
}
71+
}
72+
//// [index.js]
73+
var j = require("./package.json");
74+
module.exports = j;
75+
76+
77+
//// [package.d.ts]
78+
export declare const name: string;
79+
export declare const version: string;
80+
export declare const description: string;
81+
export declare const main: string;
82+
export declare namespace bin {
83+
export const cli: string;
84+
}
85+
export declare namespace engines {
86+
export const node: string;
87+
}
88+
export declare namespace scripts {
89+
export const scriptname: string;
90+
}
91+
export declare const devDependencies: {
92+
"@ns/dep": string;
93+
};
94+
export declare namespace dependencies {
95+
export const dep: string;
96+
}
97+
export declare const repository: string;
98+
export declare const keywords: string[];
99+
export declare const author: string;
100+
export declare const license: string;
101+
export declare const homepage: string;
102+
export declare namespace config {
103+
export const o: string[];
104+
}
105+
//// [index.d.ts]
106+
declare const j: {
107+
"name": string;
108+
"version": string;
109+
"description": string;
110+
"main": string;
111+
"bin": {
112+
"cli": string;
113+
};
114+
"engines": {
115+
"node": string;
116+
};
117+
"scripts": {
118+
"scriptname": string;
119+
};
120+
"devDependencies": {
121+
"@ns/dep": string;
122+
};
123+
"dependencies": {
124+
"dep": string;
125+
};
126+
"repository": string;
127+
"keywords": string[];
128+
"author": string;
129+
"license": string;
130+
"homepage": string;
131+
"config": {
132+
"o": string[];
133+
};
134+
};
135+
export = j;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
=== tests/cases/conformance/jsdoc/declarations/index.js ===
2+
const j = require("./package.json");
3+
>j : Symbol(j, Decl(index.js, 0, 5))
4+
>require : Symbol(require)
5+
>"./package.json" : Symbol("tests/cases/conformance/jsdoc/declarations/package", Decl(package.json, 0, 0))
6+
7+
module.exports = j;
8+
>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0))
9+
>module : Symbol(export=, Decl(index.js, 0, 36))
10+
>exports : Symbol(export=, Decl(index.js, 0, 36))
11+
>j : Symbol(j, Decl(index.js, 0, 5))
12+
13+
=== tests/cases/conformance/jsdoc/declarations/package.json ===
14+
{
15+
"name": "pkg",
16+
>"name" : Symbol("name", Decl(package.json, 0, 1))
17+
18+
"version": "0.1.0",
19+
>"version" : Symbol("version", Decl(package.json, 1, 18))
20+
21+
"description": "A package",
22+
>"description" : Symbol("description", Decl(package.json, 2, 23))
23+
24+
"main": "./dist/index.js",
25+
>"main" : Symbol("main", Decl(package.json, 3, 31))
26+
27+
"bin": {
28+
>"bin" : Symbol("bin", Decl(package.json, 4, 30))
29+
30+
"cli": "./bin/cli.js",
31+
>"cli" : Symbol("cli", Decl(package.json, 5, 12))
32+
33+
},
34+
"engines": {
35+
>"engines" : Symbol("engines", Decl(package.json, 7, 6))
36+
37+
"node": ">=0"
38+
>"node" : Symbol("node", Decl(package.json, 8, 16))
39+
40+
},
41+
"scripts": {
42+
>"scripts" : Symbol("scripts", Decl(package.json, 10, 6))
43+
44+
"scriptname": "run && run again",
45+
>"scriptname" : Symbol("scriptname", Decl(package.json, 11, 16))
46+
47+
},
48+
"devDependencies": {
49+
>"devDependencies" : Symbol("devDependencies", Decl(package.json, 13, 6))
50+
51+
"@ns/dep": "0.1.2",
52+
>"@ns/dep" : Symbol("@ns/dep", Decl(package.json, 14, 24))
53+
54+
},
55+
"dependencies": {
56+
>"dependencies" : Symbol("dependencies", Decl(package.json, 16, 6))
57+
58+
"dep": "1.2.3",
59+
>"dep" : Symbol("dep", Decl(package.json, 17, 21))
60+
61+
},
62+
"repository": "microsoft/TypeScript",
63+
>"repository" : Symbol("repository", Decl(package.json, 19, 6))
64+
65+
"keywords": [
66+
>"keywords" : Symbol("keywords", Decl(package.json, 20, 41))
67+
68+
"kw"
69+
],
70+
"author": "Auth",
71+
>"author" : Symbol("author", Decl(package.json, 23, 6))
72+
73+
"license": "See Licensce",
74+
>"license" : Symbol("license", Decl(package.json, 24, 21))
75+
76+
"homepage": "https://site",
77+
>"homepage" : Symbol("homepage", Decl(package.json, 25, 30))
78+
79+
"config": {
80+
>"config" : Symbol("config", Decl(package.json, 26, 31))
81+
82+
"o": ["a"]
83+
>"o" : Symbol("o", Decl(package.json, 27, 15))
84+
}
85+
}
86+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
=== tests/cases/conformance/jsdoc/declarations/index.js ===
2+
const j = require("./package.json");
3+
>j : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; }
4+
>require("./package.json") : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; }
5+
>require : any
6+
>"./package.json" : "./package.json"
7+
8+
module.exports = j;
9+
>module.exports = j : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; }
10+
>module.exports : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; }
11+
>module : { "tests/cases/conformance/jsdoc/declarations/index": { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; }; }
12+
>exports : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; }
13+
>j : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; }
14+
15+
=== tests/cases/conformance/jsdoc/declarations/package.json ===
16+
{
17+
>{ "name": "pkg", "version": "0.1.0", "description": "A package", "main": "./dist/index.js", "bin": { "cli": "./bin/cli.js", }, "engines": { "node": ">=0" }, "scripts": { "scriptname": "run && run again", }, "devDependencies": { "@ns/dep": "0.1.2", }, "dependencies": { "dep": "1.2.3", }, "repository": "microsoft/TypeScript", "keywords": [ "kw" ], "author": "Auth", "license": "See Licensce", "homepage": "https://site", "config": { "o": ["a"] }} : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; }
18+
19+
"name": "pkg",
20+
>"name" : string
21+
>"pkg" : "pkg"
22+
23+
"version": "0.1.0",
24+
>"version" : string
25+
>"0.1.0" : "0.1.0"
26+
27+
"description": "A package",
28+
>"description" : string
29+
>"A package" : "A package"
30+
31+
"main": "./dist/index.js",
32+
>"main" : string
33+
>"./dist/index.js" : "./dist/index.js"
34+
35+
"bin": {
36+
>"bin" : { "cli": string; }
37+
>{ "cli": "./bin/cli.js", } : { "cli": string; }
38+
39+
"cli": "./bin/cli.js",
40+
>"cli" : string
41+
>"./bin/cli.js" : "./bin/cli.js"
42+
43+
},
44+
"engines": {
45+
>"engines" : { "node": string; }
46+
>{ "node": ">=0" } : { "node": string; }
47+
48+
"node": ">=0"
49+
>"node" : string
50+
>">=0" : ">=0"
51+
52+
},
53+
"scripts": {
54+
>"scripts" : { "scriptname": string; }
55+
>{ "scriptname": "run && run again", } : { "scriptname": string; }
56+
57+
"scriptname": "run && run again",
58+
>"scriptname" : string
59+
>"run && run again" : "run && run again"
60+
61+
},
62+
"devDependencies": {
63+
>"devDependencies" : { "@ns/dep": string; }
64+
>{ "@ns/dep": "0.1.2", } : { "@ns/dep": string; }
65+
66+
"@ns/dep": "0.1.2",
67+
>"@ns/dep" : string
68+
>"0.1.2" : "0.1.2"
69+
70+
},
71+
"dependencies": {
72+
>"dependencies" : { "dep": string; }
73+
>{ "dep": "1.2.3", } : { "dep": string; }
74+
75+
"dep": "1.2.3",
76+
>"dep" : string
77+
>"1.2.3" : "1.2.3"
78+
79+
},
80+
"repository": "microsoft/TypeScript",
81+
>"repository" : string
82+
>"microsoft/TypeScript" : "microsoft/TypeScript"
83+
84+
"keywords": [
85+
>"keywords" : string[]
86+
>[ "kw" ] : string[]
87+
88+
"kw"
89+
>"kw" : "kw"
90+
91+
],
92+
"author": "Auth",
93+
>"author" : string
94+
>"Auth" : "Auth"
95+
96+
"license": "See Licensce",
97+
>"license" : string
98+
>"See Licensce" : "See Licensce"
99+
100+
"homepage": "https://site",
101+
>"homepage" : string
102+
>"https://site" : "https://site"
103+
104+
"config": {
105+
>"config" : { "o": string[]; }
106+
>{ "o": ["a"] } : { "o": string[]; }
107+
108+
"o": ["a"]
109+
>"o" : string[]
110+
>["a"] : string[]
111+
>"a" : "a"
112+
}
113+
}
114+

tests/baselines/reference/requireOfJsonFileWithDeclaration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (x) {
3333

3434

3535
//// [out/b.d.ts]
36-
declare const a: boolean;
37-
declare const b: string;
36+
export declare const a: boolean;
37+
export declare const b: string;
3838
//// [out/file1.d.ts]
3939
export {};

0 commit comments

Comments
 (0)