|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be |
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
| 8 | +import {fromObject} from 'convert-source-map'; |
8 | 9 | import MagicString from 'magic-string'; |
| 10 | +import {encode} from 'sourcemap-codec'; |
9 | 11 | import * as ts from 'typescript'; |
10 | 12 |
|
11 | 13 | import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system'; |
@@ -195,5 +197,47 @@ runInEachFileSystem(() => { |
195 | 197 | result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts'))!; |
196 | 198 | expect(typingsFile.contents).toContain(`\n// ADD MODUlE WITH PROVIDERS PARAMS\n`); |
197 | 199 | }); |
| 200 | + |
| 201 | + it('should render an external source map for files whose original file does not have a source map', |
| 202 | + () => { |
| 203 | + const { |
| 204 | + renderer, |
| 205 | + decorationAnalyses, |
| 206 | + privateDeclarationsAnalyses, |
| 207 | + moduleWithProvidersAnalyses |
| 208 | + } = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]); |
| 209 | + |
| 210 | + const result = renderer.renderProgram( |
| 211 | + decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses); |
| 212 | + |
| 213 | + const typingsFile = |
| 214 | + result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts'))!; |
| 215 | + expect(typingsFile.contents).toContain('//# sourceMappingURL=file.d.ts.map'); |
| 216 | + }); |
| 217 | + |
| 218 | + it('should render an internal source map for files whose original file has an internal source map', |
| 219 | + () => { |
| 220 | + const sourceMap = fromObject({ |
| 221 | + 'version': 3, |
| 222 | + 'file': 'file.d.ts', |
| 223 | + 'sources': ['file.d.ts'], |
| 224 | + 'names': [], |
| 225 | + 'mappings': encode([[]]), |
| 226 | + 'sourcesContent': [INPUT_DTS_PROGRAM.contents], |
| 227 | + }); |
| 228 | + INPUT_DTS_PROGRAM.contents += sourceMap.toComment(); |
| 229 | + const { |
| 230 | + renderer, |
| 231 | + decorationAnalyses, |
| 232 | + privateDeclarationsAnalyses, |
| 233 | + moduleWithProvidersAnalyses |
| 234 | + } = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]); |
| 235 | + const result = renderer.renderProgram( |
| 236 | + decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses); |
| 237 | + |
| 238 | + const typingsFile = |
| 239 | + result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts'))!; |
| 240 | + expect(typingsFile.contents).toContain('//# sourceMappingURL=data:application/json'); |
| 241 | + }); |
198 | 242 | }); |
199 | 243 | }); |
0 commit comments