Skip to content

Commit 301749b

Browse files
committed
Ensure JS map are loaded correctly #996
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent b83ad5f commit 301749b

File tree

19 files changed

+523
-15
lines changed

19 files changed

+523
-15
lines changed

src/textcode/analysis.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def text_lines(location, demarkup=False):
115115

116116
if T.is_js_map:
117117
try:
118-
return js_map_sources_lines(location)
118+
return list(js_map_sources_lines(location))
119119
except:
120-
# try again later with as plain text
120+
# try again later with as plain text otherwise
121121
pass
122122

123123
if T.is_text:
@@ -203,10 +203,10 @@ def js_map_sources_lines(location):
203203
"""
204204
with codecs.open(location, 'rb', encoding='utf-8') as jsm:
205205
content = json.load(jsm)
206-
sources = content['sourcesContent']
207-
for entry in sources:
208-
for line in entry.splitlines():
209-
yield line
206+
sources = content.get('sourcesContent', [])
207+
for entry in sources:
208+
for line in entry.splitlines():
209+
yield line
210210

211211

212212
def as_unicode(line):

tests/licensedcode/data/licenses/ar-ER.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
licenses:
2+
- mit

tests/textcode/data/analysis/jsmap/angular-sanitize.min.js.map

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

tests/textcode/data/analysis/jsmap/ar-ER.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
"/**",
3+
" * @license",
4+
" * Copyright Google Inc. All Rights Reserved.",
5+
" *",
6+
" * Use of this source code is governed by an MIT-style license that can be",
7+
" * found in the LICENSE file at https://angular.io/license",
8+
" */",
9+
"",
10+
"// THIS CODE IS GENERATED - DO NOT MODIFY",
11+
"// See angular/tools/gulp-tasks/cldr/extract.js",
12+
"",
13+
"export default [",
14+
" [",
15+
" [",
16+
" '\u0641\u062c\u0631\u064b\u0627', '\u0635\u0628\u0627\u062d\u064b\u0627', '\u0638\u0647\u0631\u064b\u0627', '\u0628\u0639\u062f \u0627\u0644\u0638\u0647\u0631', '\u0645\u0633\u0627\u0621\u064b',",
17+
" '\u0645\u0646\u062a\u0635\u0641 \u0627\u0644\u0644\u064a\u0644', '\u0644\u064a\u0644\u0627\u064b'",
18+
" ],",
19+
" [",
20+
" '\u0641\u062c\u0631\u064b\u0627', '\u0635', '\u0638\u0647\u0631\u064b\u0627', '\u0628\u0639\u062f \u0627\u0644\u0638\u0647\u0631', '\u0645\u0633\u0627\u0621\u064b', '\u0645\u0646\u062a\u0635\u0641 \u0627\u0644\u0644\u064a\u0644',",
21+
" '\u0644\u064a\u0644\u0627\u064b'",
22+
" ],",
23+
" [",
24+
" '\u0641\u062c\u0631\u064b\u0627', '\u0635\u0628\u0627\u062d\u064b\u0627', '\u0638\u0647\u0631\u064b\u0627', '\u0628\u0639\u062f \u0627\u0644\u0638\u0647\u0631', '\u0645\u0633\u0627\u0621\u064b',",
25+
" '\u0645\u0646\u062a\u0635\u0641 \u0627\u0644\u0644\u064a\u0644', '\u0644\u064a\u0644\u0627\u064b'",
26+
" ]",
27+
" ],",
28+
" ,",
29+
" [",
30+
" ['03:00', '06:00'], ['06:00', '12:00'], ['12:00', '13:00'], ['13:00', '18:00'],",
31+
" ['18:00', '24:00'], ['00:00', '01:00'], ['01:00', '03:00']",
32+
" ]",
33+
"];"
34+
]

tests/textcode/data/analysis/jsmap/broken.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
"{\"version\":3,\"file\":\"ar-ER.js\",\"sourceRoot:\"\",\"sources\":[\"",
3+
"../../../../../packages/common/locales/extra/ar-ER.ts\"],\"names\":[],\"mappings\":\";;;;;;;AAWA,eAAe;IACb;QACE;YACE,OAAO,EAAE,QAAQ,EAAE,OAAO,",
4+
"EAAE,WAAW,EAAE,OAAO;YAChD,aAAa,EAAE,OAAO;SACvB;QACD;YACE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,",
5+
"OAAO,EAAE,aAAa;YAC1D,OAAO;SACR;QACD;YACE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO;YAChD,aAAa,EAAE,",
6+
"OAAO;SACvB;KACF;IACD,AADE;IAEF;QACE,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,",
7+
"OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;QAC9E,CAAC,OAAO,EAAE,OAAO,CAAC,",
8+
"EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;KAC3D;CACF,CAAC\",\"",
9+
"sourcesContent\":[\"/** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ // THIS CODE IS GENERATED - DO NOT MODIFY // See angular/tools/gulp-tasks/cldr/extract.js export default [ [ [ '\u0641\u062c\u0631\u064b\u0627', '\u0635\u0628\u0627\u062d\u064b\u0627', '\u0638\u0647\u0631\u064b\u0627', '\u0628\u0639\u062f \u0627\u0644\u0638\u0647\u0631', '",
10+
"\u0645\u0633\u0627\u0621\u064b', '\u0645\u0646\u062a\u0635\u0641 \u0627\u0644\u0644\u064a\u0644', '\u0644\u064a\u0644\u0627\u064b' ], [ '\u0641\u062c\u0631\u064b\u0627', '\u0635', '",
11+
"\u0638\u0647\u0631\u064b\u0627', '\u0628\u0639\u062f \u0627\u0644\u0638\u0647\u0631', '\u0645\u0633\u0627\u0621\u064b', '\u0645\u0646\u062a\u0635\u0641 \u0627\u0644\u0644\u064a\u0644', '\u0644\u064a\u0644\u0627\u064b' ], [ '",
12+
"\u0641\u062c\u0631\u064b\u0627', '\u0635\u0628\u0627\u062d\u064b\u0627', '\u0638\u0647\u0631\u064b\u0627', '\u0628\u0639\u062f \u0627\u0644\u0638\u0647\u0631', '\u0645\u0633\u0627\u0621\u064b', '",
13+
"\u0645\u0646\u062a\u0635\u0641 \u0627\u0644\u0644\u064a\u0644', '\u0644\u064a\u0644\u0627\u064b' ] ], , [ ['03:00', '06:00'], ['06:00',",
14+
" '12:00'], ['12:00', '13:00'], ['13:00', '18:00'],",
15+
" ['18:00', '24:00'], ['00:00', '01:00'], ['01:00',",
16+
" '03:00'] ] ]; \"]}"
17+
]

tests/textcode/data/analysis/jsmap/button.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)