@@ -6825,6 +6825,7 @@ def test_source_map(self):
6825
6825
dirname = self .get_dir ()
6826
6826
src_filename = os .path .join (dirname , 'src.cpp' )
6827
6827
out_filename = os .path .join (dirname , 'a.out.js' )
6828
+ wasm_filename = os .path .join (dirname , 'a.out.wasm' )
6828
6829
no_maps_filename = os .path .join (dirname , 'no-maps.out.js' )
6829
6830
6830
6831
with open (src_filename , 'w' ) as f : f .write (src )
@@ -6842,12 +6843,13 @@ def build_and_check():
6842
6843
import json
6843
6844
Building .emcc (src_filename , Settings .serialize () + self .emcc_args +
6844
6845
Building .COMPILER_TEST_OPTS , out_filename , stderr = PIPE )
6846
+ map_referent = out_filename if not Settings .BINARYEN else wasm_filename
6845
6847
# after removing the @line and @sourceMappingURL comments, the build
6846
6848
# result should be identical to the non-source-mapped debug version.
6847
6849
# this is worth checking because the parser AST swaps strings for token
6848
6850
# objects when generating source maps, so we want to make sure the
6849
6851
# optimizer can deal with both types.
6850
- map_filename = out_filename + '.map'
6852
+ map_filename = map_referent + '.map'
6851
6853
6852
6854
def encode_utf8 (data ):
6853
6855
if isinstance (data , dict ):
@@ -6864,10 +6866,16 @@ def encode_utf8(data):
6864
6866
return data
6865
6867
6866
6868
data = encode_utf8 (json .load (open (map_filename , 'r' )))
6867
- self .assertPathsIdentical (out_filename , data ['file' ])
6869
+ if hasattr (data , 'file' ):
6870
+ # the file attribute is optional, but if it is present it needs to refer
6871
+ # the output file.
6872
+ self .assertPathsIdentical (map_referent , data ['file' ])
6868
6873
assert len (data ['sources' ]) == 1 , data ['sources' ]
6869
6874
self .assertPathsIdentical (src_filename , data ['sources' ][0 ])
6870
- self .assertTextDataIdentical (src , data ['sourcesContent' ][0 ])
6875
+ if hasattr (data , 'sourcesContent' ):
6876
+ # the sourcesContent attribute is optional, but if it is present it
6877
+ # needs to containt valid source text.
6878
+ self .assertTextDataIdentical (src , data ['sourcesContent' ][0 ])
6871
6879
mappings = encode_utf8 (json .loads (jsrun .run_js (
6872
6880
path_from_root ('tools' , 'source-maps' , 'sourcemap2json.js' ),
6873
6881
tools .shared .NODE_JS , [map_filename ])))
0 commit comments