File tree Expand file tree Collapse file tree
integration/sourcemap-typescript-nested Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,16 +3,37 @@ const lineCounter = require('./utils/lineCounter');
33
44class SourceMap {
55 constructor ( mappings , sources ) {
6- this . mappings = mappings || [ ] ;
6+ this . mappings = this . purifyMappings ( mappings ) ;
77 this . sources = sources || { } ;
88 this . lineCount = null ;
99 }
1010
11+ purifyMappings ( mappings ) {
12+ if ( Array . isArray ( mappings ) ) {
13+ return mappings . filter ( mapping => {
14+ return (
15+ mapping &&
16+ mapping . source &&
17+ mapping . original &&
18+ typeof mapping . original . line === 'number' &&
19+ mapping . original . line > 0 &&
20+ typeof mapping . original . column === 'number' &&
21+ mapping . generated &&
22+ typeof mapping . generated . line === 'number' &&
23+ mapping . generated . line > 0 &&
24+ typeof mapping . generated . column === 'number'
25+ ) ;
26+ } ) ;
27+ }
28+
29+ return [ ] ;
30+ }
31+
1132 async getConsumer ( map ) {
1233 if ( map instanceof SourceMapConsumer ) {
1334 return map ;
1435 }
15-
36+ map = typeof map === 'string' ? JSON . parse ( map ) : map ;
1637 return await new SourceMapConsumer ( map ) ;
1738 }
1839
Original file line number Diff line number Diff line change 1+ import { local } from './local' ;
2+
3+ export function env ( ) {
4+ return local ;
5+ }
Original file line number Diff line number Diff line change 1+ exports . local = process . env . NODE_ENV ;
Original file line number Diff line number Diff line change @@ -61,6 +61,35 @@ describe('sourcemaps', function() {
6161 assert . equal ( output . env ( ) , process . env . NODE_ENV ) ;
6262 } ) ;
6363
64+ it ( 'should create a valid sourcemap as a child of a nested TS bundle' , async function ( ) {
65+ let b = await bundle (
66+ __dirname + '/integration/sourcemap-typescript-nested/index.ts'
67+ ) ;
68+
69+ assertBundleTree ( b , {
70+ name : 'index.js' ,
71+ assets : [ 'index.ts' , 'local.ts' ] ,
72+ childBundles : [
73+ {
74+ name : 'index.map' ,
75+ type : 'map'
76+ }
77+ ]
78+ } ) ;
79+
80+ let raw = fs
81+ . readFileSync ( path . join ( __dirname , '/dist/index.js' ) )
82+ . toString ( ) ;
83+ let map = fs
84+ . readFileSync ( path . join ( __dirname , '/dist/index.map' ) )
85+ . toString ( ) ;
86+ mapValidator ( raw , map ) ;
87+
88+ let output = run ( b ) ;
89+ assert . equal ( typeof output . env , 'function' ) ;
90+ assert . equal ( output . env ( ) , process . env . NODE_ENV ) ;
91+ } ) ;
92+
6493 it ( 'should create a valid sourcemap for a js file with requires' , async function ( ) {
6594 let b = await bundle ( __dirname + '/integration/sourcemap-nested/index.js' ) ;
6695
You can’t perform that action at this time.
0 commit comments