fix(compiler): update type castings for JSON.parse usage (#40710)
Update usages of JSON.parse to be cast as specific types. PR Close #40710
This commit is contained in:
parent
b75d7cb11f
commit
f728490222
|
@ -1,6 +1,6 @@
|
||||||
load("//tools:defaults.bzl", "protractor_web_test_suite", "ts_library")
|
load("//tools:defaults.bzl", "protractor_web_test_suite", "ts_library")
|
||||||
|
|
||||||
def example_test(name, srcs, server, data = [], **kwargs):
|
def example_test(name, srcs, server, data = [], deps = [], **kwargs):
|
||||||
ts_library(
|
ts_library(
|
||||||
name = "%s_lib" % name,
|
name = "%s_lib" % name,
|
||||||
testonly = True,
|
testonly = True,
|
||||||
|
@ -12,7 +12,7 @@ def example_test(name, srcs, server, data = [], **kwargs):
|
||||||
"@npm//@types/jasminewd2",
|
"@npm//@types/jasminewd2",
|
||||||
"@npm//@types/selenium-webdriver",
|
"@npm//@types/selenium-webdriver",
|
||||||
"@npm//protractor",
|
"@npm//protractor",
|
||||||
],
|
] + deps,
|
||||||
)
|
)
|
||||||
|
|
||||||
protractor_web_test_suite(
|
protractor_web_test_suite(
|
||||||
|
|
|
@ -8,4 +8,7 @@ example_test(
|
||||||
"//modules/playground/src/sourcemap:index.ts",
|
"//modules/playground/src/sourcemap:index.ts",
|
||||||
],
|
],
|
||||||
server = "//modules/playground/src/sourcemap:devserver",
|
server = "//modules/playground/src/sourcemap:devserver",
|
||||||
|
deps = [
|
||||||
|
"@npm//source-map",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {readFileSync} from 'fs';
|
||||||
import {$, browser} from 'protractor';
|
import {$, browser} from 'protractor';
|
||||||
import {logging} from 'selenium-webdriver';
|
import {logging} from 'selenium-webdriver';
|
||||||
|
import {RawSourceMap, SourceMapConsumer} from 'source-map';
|
||||||
const fs = require('fs');
|
|
||||||
const sourceMap = require('source-map');
|
|
||||||
|
|
||||||
describe('sourcemaps', function() {
|
describe('sourcemaps', function() {
|
||||||
const URL = '/';
|
const URL = '/';
|
||||||
|
@ -36,17 +35,16 @@ describe('sourcemaps', function() {
|
||||||
|
|
||||||
|
|
||||||
const content =
|
const content =
|
||||||
fs.readFileSync(require.resolve('../../src/sourcemap/index.js')).toString('utf8');
|
readFileSync(require.resolve('../../src/sourcemap/index.js')).toString('utf8');
|
||||||
const marker = '//# sourceMappingURL=data:application/json;base64,';
|
const marker = '//# sourceMappingURL=data:application/json;base64,';
|
||||||
const index = content.indexOf(marker);
|
const index = content.indexOf(marker);
|
||||||
const sourceMapData =
|
const sourceMapData =
|
||||||
Buffer.from(content.substring(index + marker.length), 'base64').toString('utf8');
|
Buffer.from(content.substring(index + marker.length), 'base64').toString('utf8');
|
||||||
|
|
||||||
const decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));
|
const decoder = new SourceMapConsumer(JSON.parse(sourceMapData) as RawSourceMap);
|
||||||
|
|
||||||
const originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn});
|
const originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn});
|
||||||
|
const sourceCodeLines = readFileSync(require.resolve('../../src/sourcemap/index.ts'), {
|
||||||
const sourceCodeLines = fs.readFileSync(require.resolve('../../src/sourcemap/index.ts'), {
|
|
||||||
encoding: 'UTF-8'
|
encoding: 'UTF-8'
|
||||||
}).split('\n');
|
}).split('\n');
|
||||||
expect(sourceCodeLines[originalPosition.line - 1])
|
expect(sourceCodeLines[originalPosition.line - 1])
|
||||||
|
|
|
@ -461,7 +461,7 @@ class FromJsonDeserializer extends ValueTransformer {
|
||||||
summaries: Summary<StaticSymbol>[],
|
summaries: Summary<StaticSymbol>[],
|
||||||
importAs: {symbol: StaticSymbol, importAs: StaticSymbol}[]
|
importAs: {symbol: StaticSymbol, importAs: StaticSymbol}[]
|
||||||
} {
|
} {
|
||||||
const data: {moduleName: string|null, summaries: any[], symbols: any[]} = JSON.parse(json);
|
const data = JSON.parse(json) as {moduleName: string | null, summaries: any[], symbols: any[]};
|
||||||
const allImportAs: {symbol: StaticSymbol, importAs: StaticSymbol}[] = [];
|
const allImportAs: {symbol: StaticSymbol, importAs: StaticSymbol}[] = [];
|
||||||
this.symbols = data.symbols.map(
|
this.symbols = data.symbols.map(
|
||||||
(serializedSymbol) => this.symbolCache.get(
|
(serializedSymbol) => this.symbolCache.get(
|
||||||
|
|
|
@ -427,7 +427,7 @@ export class MockAotCompilerHost implements AotCompilerHost {
|
||||||
if (this.metadataVisible) {
|
if (this.metadataVisible) {
|
||||||
const metadataPath = modulePath.replace(DTS, '.metadata.json');
|
const metadataPath = modulePath.replace(DTS, '.metadata.json');
|
||||||
if (this.tsHost.fileExists(metadataPath)) {
|
if (this.tsHost.fileExists(metadataPath)) {
|
||||||
let result = JSON.parse(this.tsHost.readFile(metadataPath));
|
let result = JSON.parse(this.tsHost.readFile(metadataPath)) as {[key: string]: any}[];
|
||||||
return Array.isArray(result) ? result : [result];
|
return Array.isArray(result) ? result : [result];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue