1namespace ts { 2 describe("unittests:: tsbuild:: javascriptProjectEmit::", () => { 3 verifyTsc({ 4 scenario: "javascriptProjectEmit", 5 subScenario: `loads js-based projects and emits them correctly`, 6 fs: () => loadProjectFromFiles({ 7 "/src/common/nominal.js": Utils.dedent` 8 /** 9 * @template T, Name 10 * @typedef {T & {[Symbol.species]: Name}} Nominal 11 */ 12 module.exports = {}; 13 `, 14 "/src/common/tsconfig.json": Utils.dedent` 15 { 16 "extends": "../tsconfig.base.json", 17 "compilerOptions": { 18 "composite": true 19 }, 20 "include": ["nominal.js"] 21 }`, 22 "/src/sub-project/index.js": Utils.dedent` 23 import { Nominal } from '../common/nominal'; 24 25 /** 26 * @typedef {Nominal<string, 'MyNominal'>} MyNominal 27 */ 28 `, 29 "/src/sub-project/tsconfig.json": Utils.dedent` 30 { 31 "extends": "../tsconfig.base.json", 32 "compilerOptions": { 33 "composite": true 34 }, 35 "references": [ 36 { "path": "../common" } 37 ], 38 "include": ["./index.js"] 39 }`, 40 "/src/sub-project-2/index.js": Utils.dedent` 41 import { MyNominal } from '../sub-project/index'; 42 43 const variable = { 44 key: /** @type {MyNominal} */('value'), 45 }; 46 47 /** 48 * @return {keyof typeof variable} 49 */ 50 export function getVar() { 51 return 'key'; 52 } 53 `, 54 "/src/sub-project-2/tsconfig.json": Utils.dedent` 55 { 56 "extends": "../tsconfig.base.json", 57 "compilerOptions": { 58 "composite": true 59 }, 60 "references": [ 61 { "path": "../sub-project" } 62 ], 63 "include": ["./index.js"] 64 }`, 65 "/src/tsconfig.json": Utils.dedent` 66 { 67 "compilerOptions": { 68 "composite": true 69 }, 70 "references": [ 71 { "path": "./sub-project" }, 72 { "path": "./sub-project-2" } 73 ], 74 "include": [] 75 }`, 76 "/src/tsconfig.base.json": Utils.dedent` 77 { 78 "compilerOptions": { 79 "skipLibCheck": true, 80 "rootDir": "./", 81 "outDir": "../lib", 82 "allowJs": true, 83 "checkJs": true, 84 "declaration": true 85 } 86 }`, 87 }, symbolLibContent), 88 commandLineArgs: ["-b", "/src"] 89 }); 90 91 verifyTscWithEdits({ 92 scenario: "javascriptProjectEmit", 93 subScenario: `modifies outfile js projects and concatenates them correctly`, 94 fs: () => loadProjectFromFiles({ 95 "/src/common/nominal.js": Utils.dedent` 96 /** 97 * @template T, Name 98 * @typedef {T & {[Symbol.species]: Name}} Nominal 99 */ 100 `, 101 "/src/common/tsconfig.json": Utils.dedent` 102 { 103 "extends": "../tsconfig.base.json", 104 "compilerOptions": { 105 "composite": true, 106 "outFile": "common.js", 107 108 }, 109 "include": ["nominal.js"] 110 }`, 111 "/src/sub-project/index.js": Utils.dedent` 112 /** 113 * @typedef {Nominal<string, 'MyNominal'>} MyNominal 114 */ 115 const c = /** @type {*} */(null); 116 `, 117 "/src/sub-project/tsconfig.json": Utils.dedent` 118 { 119 "extends": "../tsconfig.base.json", 120 "compilerOptions": { 121 "composite": true, 122 "outFile": "sub-project.js", 123 124 }, 125 "references": [ 126 { "path": "../common", "prepend": true } 127 ], 128 "include": ["./index.js"] 129 }`, 130 "/src/sub-project-2/index.js": Utils.dedent` 131 const variable = { 132 key: /** @type {MyNominal} */('value'), 133 }; 134 135 /** 136 * @return {keyof typeof variable} 137 */ 138 function getVar() { 139 return 'key'; 140 } 141 `, 142 "/src/sub-project-2/tsconfig.json": Utils.dedent` 143 { 144 "extends": "../tsconfig.base.json", 145 "compilerOptions": { 146 "composite": true, 147 "outFile": "sub-project-2.js", 148 149 }, 150 "references": [ 151 { "path": "../sub-project", "prepend": true } 152 ], 153 "include": ["./index.js"] 154 }`, 155 "/src/tsconfig.json": Utils.dedent` 156 { 157 "compilerOptions": { 158 "composite": true, 159 "outFile": "src.js" 160 }, 161 "references": [ 162 { "path": "./sub-project", "prepend": true }, 163 { "path": "./sub-project-2", "prepend": true } 164 ], 165 "include": [] 166 }`, 167 "/src/tsconfig.base.json": Utils.dedent` 168 { 169 "compilerOptions": { 170 "skipLibCheck": true, 171 "rootDir": "./", 172 "allowJs": true, 173 "checkJs": true, 174 "declaration": true 175 } 176 }`, 177 }, symbolLibContent), 178 commandLineArgs: ["-b", "/src"], 179 edits: [{ 180 subScenario: "incremental-declaration-doesnt-change", 181 modifyFs: fs => replaceText(fs, "/src/sub-project/index.js", "null", "undefined") 182 }] 183 }); 184 185 verifyTsc({ 186 scenario: "javascriptProjectEmit", 187 subScenario: `loads js-based projects with non-moved json files and emits them correctly`, 188 fs: () => loadProjectFromFiles({ 189 "/src/common/obj.json": Utils.dedent` 190 { 191 "val": 42 192 }`, 193 "/src/common/index.ts": Utils.dedent` 194 import x = require("./obj.json"); 195 export = x; 196 `, 197 "/src/common/tsconfig.json": Utils.dedent` 198 { 199 "extends": "../tsconfig.base.json", 200 "compilerOptions": { 201 "outDir": null, 202 "composite": true 203 }, 204 "include": ["index.ts", "obj.json"] 205 }`, 206 "/src/sub-project/index.js": Utils.dedent` 207 import mod from '../common'; 208 209 export const m = mod; 210 `, 211 "/src/sub-project/tsconfig.json": Utils.dedent` 212 { 213 "extends": "../tsconfig.base.json", 214 "compilerOptions": { 215 "composite": true 216 }, 217 "references": [ 218 { "path": "../common" } 219 ], 220 "include": ["./index.js"] 221 }`, 222 "/src/sub-project-2/index.js": Utils.dedent` 223 import { m } from '../sub-project/index'; 224 225 const variable = { 226 key: m, 227 }; 228 229 export function getVar() { 230 return variable; 231 } 232 `, 233 "/src/sub-project-2/tsconfig.json": Utils.dedent` 234 { 235 "extends": "../tsconfig.base.json", 236 "compilerOptions": { 237 "composite": true 238 }, 239 "references": [ 240 { "path": "../sub-project" } 241 ], 242 "include": ["./index.js"] 243 }`, 244 "/src/tsconfig.json": Utils.dedent` 245 { 246 "compilerOptions": { 247 "composite": true 248 }, 249 "references": [ 250 { "path": "./sub-project" }, 251 { "path": "./sub-project-2" } 252 ], 253 "include": [] 254 }`, 255 "/src/tsconfig.base.json": Utils.dedent` 256 { 257 "compilerOptions": { 258 "skipLibCheck": true, 259 "rootDir": "./", 260 "outDir": "../out", 261 "allowJs": true, 262 "checkJs": true, 263 "resolveJsonModule": true, 264 "esModuleInterop": true, 265 "declaration": true 266 } 267 }`, 268 }, symbolLibContent), 269 commandLineArgs: ["-b", "/src"] 270 }); 271 }); 272} 273