From 1792bfaa20fcc1d279b84c9b32d794e567948233 Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 2 Jan 2018 10:33:00 -0800 Subject: [PATCH] source-map: Provides its own types (#22307) --- notNeededPackages.json | 6 + .../istanbul-lib-instrument-tests.ts | 5 +- types/istanbul-lib-instrument/package.json | 6 + .../istanbul-lib-source-maps-tests.ts | 5 +- types/istanbul-lib-source-maps/package.json | 6 + types/rollup/package.json | 6 + types/source-map/index.d.ts | 334 ------------------ types/source-map/source-map-tests.ts | 206 ----------- types/source-map/tsconfig.json | 23 -- types/source-map/tslint.json | 7 - types/uglify-js/package.json | 6 + types/webpack-sources/package.json | 6 + 12 files changed, 42 insertions(+), 574 deletions(-) create mode 100644 types/istanbul-lib-instrument/package.json create mode 100644 types/istanbul-lib-source-maps/package.json create mode 100644 types/rollup/package.json delete mode 100644 types/source-map/index.d.ts delete mode 100644 types/source-map/source-map-tests.ts delete mode 100644 types/source-map/tsconfig.json delete mode 100644 types/source-map/tslint.json create mode 100644 types/uglify-js/package.json create mode 100644 types/webpack-sources/package.json diff --git a/notNeededPackages.json b/notNeededPackages.json index 580a4dce60..f62f91bfe4 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -1116,6 +1116,12 @@ "sourceRepoURL": "https://www.npmjs.com/package/soap", "asOfVersion": "0.21.0" }, + { + "libraryName": "source-map", + "typingsPackageName": "source-map", + "sourceRepoURL": "https://github.com/mozilla/source-map", + "asOfVersion": "0.5.7" + }, { "libraryName": "Spin.js", "typingsPackageName": "spin.js", diff --git a/types/istanbul-lib-instrument/istanbul-lib-instrument-tests.ts b/types/istanbul-lib-instrument/istanbul-lib-instrument-tests.ts index 54d66314d4..2a4ac328c2 100644 --- a/types/istanbul-lib-instrument/istanbul-lib-instrument-tests.ts +++ b/types/istanbul-lib-instrument/istanbul-lib-instrument-tests.ts @@ -5,6 +5,7 @@ import { } from 'istanbul-lib-instrument'; import * as babelTypes from 'babel-types'; +import { RawSourceMap } from 'source-map'; const code = 'foo'; const filename = 'bar.txt'; @@ -24,8 +25,8 @@ const instrumenter = createInstrumenter({ debug: false }); -const sourceMap = { - version: 1, +const sourceMap: RawSourceMap = { + version: 1 as any as string, // Fixed by https://github.com/mozilla/source-map/pull/293 but the fix is not yet published sources: ['foo', 'bar'], names: ['foo', 'bar'], mappings: 'foo', diff --git a/types/istanbul-lib-instrument/package.json b/types/istanbul-lib-instrument/package.json new file mode 100644 index 0000000000..100334a89f --- /dev/null +++ b/types/istanbul-lib-instrument/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "source-map": "^0.6.1" + } +} diff --git a/types/istanbul-lib-source-maps/istanbul-lib-source-maps-tests.ts b/types/istanbul-lib-source-maps/istanbul-lib-source-maps-tests.ts index be03e785fc..844205df8d 100644 --- a/types/istanbul-lib-source-maps/istanbul-lib-source-maps-tests.ts +++ b/types/istanbul-lib-source-maps/istanbul-lib-source-maps-tests.ts @@ -1,5 +1,6 @@ import { createSourceMapStore } from 'istanbul-lib-source-maps'; import { CoverageMap } from 'istanbul-lib-coverage'; +import { RawSourceMap } from 'source-map'; createSourceMapStore(); createSourceMapStore({}); @@ -12,8 +13,8 @@ const store = createSourceMapStore({ store.data['foo'].type.trim(); -const sourceMap = { - version: 1, +const sourceMap: RawSourceMap = { + version: 1 as any as string, // Fixed by https://github.com/mozilla/source-map/pull/293 but the fix is not yet published sources: ['foo', 'bar'], names: ['foo', 'bar'], mappings: 'foo', diff --git a/types/istanbul-lib-source-maps/package.json b/types/istanbul-lib-source-maps/package.json new file mode 100644 index 0000000000..100334a89f --- /dev/null +++ b/types/istanbul-lib-source-maps/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "source-map": "^0.6.1" + } +} diff --git a/types/rollup/package.json b/types/rollup/package.json new file mode 100644 index 0000000000..100334a89f --- /dev/null +++ b/types/rollup/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "source-map": "^0.6.1" + } +} diff --git a/types/source-map/index.d.ts b/types/source-map/index.d.ts deleted file mode 100644 index ae1f025860..0000000000 --- a/types/source-map/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -// Type definitions for source-map 0.5 -// Project: https://github.com/mozilla/source-map -// Definitions by: Morten Houston Ludvigsen , -// Ron Buckton -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -export as namespace sourceMap; - -export type SourceMapUrl = string; - -export interface StartOfSourceMap { - file?: string; - sourceRoot?: string; - skipValidation?: boolean; -} - -export interface RawSourceMap { - version: number; - sources: string[]; - names: string[]; - sourceRoot?: string; - sourcesContent?: string[]; - mappings: string; - file: string; -} - -export interface RawIndexMap extends StartOfSourceMap { - version: number; - sections: RawSection[]; -} - -export interface RawSection { - offset: Position; - map: RawSourceMap; -} - -export interface Position { - line: number; - column: number; -} - -export interface NullablePosition { - line: number | null; - column: number | null; - lastColumn: number | null; -} - -export interface MappedPosition { - source: string; - line: number; - column: number; - name?: string; -} - -export interface NullableMappedPosition { - source: string | null; - line: number | null; - column: number | null; - name: string | null; -} - -export interface MappingItem { - source: string; - generatedLine: number; - generatedColumn: number; - originalLine: number; - originalColumn: number; - name: string; -} - -export interface Mapping { - generated: Position; - original: Position; - source: string; - name?: string; -} - -export interface CodeWithSourceMap { - code: string; - map: SourceMapGenerator; -} - -export interface SourceMapConsumer { - /** - * Compute the last column for each generated mapping. The last column is - * inclusive. - */ - computeColumnSpans(): void; - - /** - * Returns the original source, line, and column information for the generated - * source's line and column positions provided. The only argument is an object - * with the following properties: - * - * - line: The line number in the generated source. - * - column: The column number in the generated source. - * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or - * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the - * closest element that is smaller than or greater than the one we are - * searching for, respectively, if the exact element cannot be found. - * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. - * - * and an object is returned with the following properties: - * - * - source: The original source file, or null. - * - line: The line number in the original source, or null. - * - column: The column number in the original source, or null. - * - name: The original identifier, or null. - */ - originalPositionFor(generatedPosition: Position & { bias?: number }): NullableMappedPosition; - - /** - * Returns the generated line and column information for the original source, - * line, and column positions provided. The only argument is an object with - * the following properties: - * - * - source: The filename of the original source. - * - line: The line number in the original source. - * - column: The column number in the original source. - * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or - * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the - * closest element that is smaller than or greater than the one we are - * searching for, respectively, if the exact element cannot be found. - * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. - * - * and an object is returned with the following properties: - * - * - line: The line number in the generated source, or null. - * - column: The column number in the generated source, or null. - */ - generatedPositionFor(originalPosition: MappedPosition & { bias?: number }): NullablePosition; - - /** - * Returns all generated line and column information for the original source, - * line, and column provided. If no column is provided, returns all mappings - * corresponding to a either the line we are searching for or the next - * closest line that has any mappings. Otherwise, returns all mappings - * corresponding to the given line and either the column we are searching for - * or the next closest column that has any offsets. - * - * The only argument is an object with the following properties: - * - * - source: The filename of the original source. - * - line: The line number in the original source. - * - column: Optional. the column number in the original source. - * - * and an array of objects is returned, each with the following properties: - * - * - line: The line number in the generated source, or null. - * - column: The column number in the generated source, or null. - */ - allGeneratedPositionsFor(originalPosition: MappedPosition): NullablePosition[]; - - /** - * Return true if we have the source content for every source in the source - * map, false otherwise. - */ - hasContentsOfAllSources(): boolean; - - /** - * Returns the original source content. The only argument is the url of the - * original source file. Returns null if no original source content is - * available. - */ - sourceContentFor(source: string, returnNullOnMissing?: boolean): string | null; - - /** - * Iterate over each mapping between an original source/line/column and a - * generated line/column in this source map. - * - * @param callback - * The function that is called with each mapping. - * @param context - * Optional. If specified, this object will be the value of `this` every - * time that `aCallback` is called. - * @param order - * Either `SourceMapConsumer.GENERATED_ORDER` or - * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to - * iterate over the mappings sorted by the generated file's line/column - * order or the original's source/line/column order, respectively. Defaults to - * `SourceMapConsumer.GENERATED_ORDER`. - */ - eachMapping(callback: (mapping: MappingItem) => void, context?: any, order?: number): void; -} - -export interface SourceMapConsumerConstructor { - prototype: SourceMapConsumer; - - GENERATED_ORDER: number; - ORIGINAL_ORDER: number; - GREATEST_LOWER_BOUND: number; - LEAST_UPPER_BOUND: number; - - new (rawSourceMap: RawSourceMap, sourceMapUrl?: SourceMapUrl): BasicSourceMapConsumer; - new (rawSourceMap: RawIndexMap, sourceMapUrl?: SourceMapUrl): IndexedSourceMapConsumer; - new (rawSourceMap: RawSourceMap | RawIndexMap | string, sourceMapUrl?: SourceMapUrl): BasicSourceMapConsumer | IndexedSourceMapConsumer; - - /** - * Create a BasicSourceMapConsumer from a SourceMapGenerator. - * - * @param sourceMap - * The source map that will be consumed. - */ - fromSourceMap(sourceMap: SourceMapGenerator, sourceMapUrl?: SourceMapUrl): BasicSourceMapConsumer; -} - -export const SourceMapConsumer: SourceMapConsumerConstructor; - -export interface BasicSourceMapConsumer extends SourceMapConsumer { - file: string; - sourceRoot: string; - sources: string[]; - sourcesContent: string[]; -} - -export interface BasicSourceMapConsumerConstructor { - prototype: BasicSourceMapConsumer; - - new (rawSourceMap: RawSourceMap | string): BasicSourceMapConsumer; - - /** - * Create a BasicSourceMapConsumer from a SourceMapGenerator. - * - * @param sourceMap - * The source map that will be consumed. - */ - fromSourceMap(sourceMap: SourceMapGenerator): BasicSourceMapConsumer; -} - -export const BasicSourceMapConsumer: BasicSourceMapConsumerConstructor; - -export interface IndexedSourceMapConsumer extends SourceMapConsumer { - sources: string[]; -} - -export interface IndexedSourceMapConsumerConstructor { - prototype: IndexedSourceMapConsumer; - - new (rawSourceMap: RawIndexMap | string): IndexedSourceMapConsumer; -} - -export const IndexedSourceMapConsumer: IndexedSourceMapConsumerConstructor; - -export class SourceMapGenerator { - constructor(startOfSourceMap?: StartOfSourceMap); - - /** - * Creates a new SourceMapGenerator based on a SourceMapConsumer - * - * @param sourceMapConsumer The SourceMap. - */ - static fromSourceMap(sourceMapConsumer: SourceMapConsumer): SourceMapGenerator; - - /** - * Add a single mapping from original source line and column to the generated - * source's line and column for this source map being created. The mapping - * object should have the following properties: - * - * - generated: An object with the generated line and column positions. - * - original: An object with the original line and column positions. - * - source: The original source file (relative to the sourceRoot). - * - name: An optional original token name for this mapping. - */ - addMapping(mapping: Mapping): void; - - /** - * Set the source content for a source file. - */ - setSourceContent(sourceFile: string, sourceContent: string): void; - - /** - * Applies the mappings of a sub-source-map for a specific source file to the - * source map being generated. Each mapping to the supplied source file is - * rewritten using the supplied source map. Note: The resolution for the - * resulting mappings is the minimium of this map and the supplied map. - * - * @param sourceMapConsumer The source map to be applied. - * @param sourceFile Optional. The filename of the source file. - * If omitted, SourceMapConsumer's file property will be used. - * @param sourceMapPath Optional. The dirname of the path to the source map - * to be applied. If relative, it is relative to the SourceMapConsumer. - * This parameter is needed when the two source maps aren't in the same - * directory, and the source map to be applied contains relative source - * paths. If so, those relative source paths need to be rewritten - * relative to the SourceMapGenerator. - */ - applySourceMap(sourceMapConsumer: SourceMapConsumer, sourceFile?: string, sourceMapPath?: string): void; - - toString(): string; - - toJSON(): RawSourceMap; -} - -export class SourceNode { - children: SourceNode[]; - sourceContents: any; - line: number; - column: number; - source: string; - name: string; - - constructor(); - constructor( - line: number | null, - column: number | null, - source: string | null, - chunks?: Array<(string | SourceNode)> | SourceNode | string, - name?: string - ); - - static fromStringWithSourceMap( - code: string, - sourceMapConsumer: SourceMapConsumer, - relativePath?: string - ): SourceNode; - - add(chunk: Array<(string | SourceNode)> | SourceNode | string): SourceNode; - - prepend(chunk: Array<(string | SourceNode)> | SourceNode | string): SourceNode; - - setSourceContent(sourceFile: string, sourceContent: string): void; - - walk(fn: (chunk: string, mapping: MappedPosition) => void): void; - - walkSourceContents(fn: (file: string, content: string) => void): void; - - join(sep: string): SourceNode; - - replaceRight(pattern: string, replacement: string): SourceNode; - - toString(): string; - - toStringWithSourceMap(startOfSourceMap?: StartOfSourceMap): CodeWithSourceMap; -} diff --git a/types/source-map/source-map-tests.ts b/types/source-map/source-map-tests.ts deleted file mode 100644 index f87194395b..0000000000 --- a/types/source-map/source-map-tests.ts +++ /dev/null @@ -1,206 +0,0 @@ -import SourceMap = require('source-map'); - -function testSourceMapConsumer() { - function testConstructor() { - let scm: SourceMap.SourceMapConsumer; - - // create with full RawSourceMap - scm = new SourceMap.SourceMapConsumer({ - version: 3, - sources: ['foo', 'bar'], - names: ['foo', 'bar'], - sourcesContent: ['foo'], - mappings: 'foo', - file: 'sdf' - }); - - scm = new SourceMap.SourceMapConsumer(JSON.stringify({ - version: 3, - sources: ['foo', 'bar'], - names: ['foo', 'bar'], - sourcesContent: ['foo'], - mappings: 'foo', - file: 'sdf' - })); - - // create with partial RawSourceMap - scm = new SourceMap.SourceMapConsumer({ - version: 3, - sources: ['foo', 'bar'], - names: ['foo', 'bar'], - mappings: 'foo', - file: 'sdf' - }); - - // create from index map - const iscm: SourceMap.IndexedSourceMapConsumer = new SourceMap.SourceMapConsumer({ - version: 3, - sections: [ - { offset: { line: 0, column: 0 }, map: { - version: 3, - sources: ['foo', 'bar'], - names: ['foo', 'bar'], - mappings: 'foo', - file: 'foo' - } } - ] - }); - - let scg: SourceMap.SourceMapGenerator; - const bscm: SourceMap.BasicSourceMapConsumer = SourceMap.SourceMapConsumer.fromSourceMap(scg); - } - - function testOriginalPositionFor(scm: SourceMap.SourceMapConsumer) { - let origPos: SourceMap.MappedPosition; - origPos = scm.originalPositionFor({ line: 42, column: 42 }); - origPos = scm.originalPositionFor({ line: 42, column: 42, bias: SourceMap.SourceMapConsumer.LEAST_UPPER_BOUND }); - } - - function testAllGeneratedPositionsFor(scm: SourceMap.SourceMapConsumer) { - let origPos: SourceMap.MappedPosition; - let origPoses: SourceMap.Position[]; - origPoses = scm.allGeneratedPositionsFor(origPos); - } - - function testGeneratedPositionFor(scm: SourceMap.SourceMapConsumer) { - let genPos: SourceMap.Position; - genPos = scm.generatedPositionFor({ line: 42, column: 42, source: 'foo' }); - genPos = scm.generatedPositionFor({ line: 42, column: 42, source: 'foo', name: 'bar' }); - genPos = scm.generatedPositionFor({ line: 42, column: 42, source: 'foo', name: 'bar', bias: SourceMap.SourceMapConsumer.LEAST_UPPER_BOUND }); - } - - function testSourceContentFor(scm: SourceMap.SourceMapConsumer) { - let content: string; - content = scm.sourceContentFor('foo'); - } - - function testEachMapping(scm: SourceMap.SourceMapConsumer) { - let x: SourceMap.MappingItem; - let context: {}; - - scm.eachMapping(mapping => { x = mapping; }); - scm.eachMapping(mapping => { x = mapping; }, context); - scm.eachMapping(mapping => { x = mapping; }, context, SourceMap.SourceMapConsumer.GENERATED_ORDER); - scm.eachMapping(mapping => { x = mapping; }, context, SourceMap.SourceMapConsumer.ORIGINAL_ORDER); - } -} - -function testSourceMapGenerator() { - function testConstructor() { - let generator: SourceMap.SourceMapGenerator; - - generator = new SourceMap.SourceMapGenerator(); - generator = new SourceMap.SourceMapGenerator({ - file: 'foo' - }); - generator = new SourceMap.SourceMapGenerator({ - sourceRoot: 'foo' - }); - generator = new SourceMap.SourceMapGenerator({ - file: 'foo', - sourceRoot: 'bar' - }); - } - - function testFromSourceMap(generator: SourceMap.SourceMapGenerator, scm: SourceMap.SourceMapConsumer) { - generator = SourceMap.SourceMapGenerator.fromSourceMap(scm); - } - - function testAddMapping(generator: SourceMap.SourceMapGenerator) { - generator.addMapping({ - generated: { line: 42, column: 42 }, - original: { line: 42, column: 42 }, - source: 'foo', - name: 'foo' - }); - - generator.addMapping({ - generated: { line: 42, column: 42 }, - original: { line: 42, column: 42 }, - source: 'foo' - }); - } - - function testSetSourceContent(generator: SourceMap.SourceMapGenerator) { - generator.setSourceContent('foo', 'bar'); - } - - function testApplySourceMap(generator: SourceMap.SourceMapGenerator, scm: SourceMap.SourceMapConsumer) { - generator.applySourceMap(scm); - generator.applySourceMap(scm, 'foo'); - generator.applySourceMap(scm, 'foo', 'bar'); - } - - function testToString(generator: SourceMap.SourceMapGenerator) { - let str: string; - str = generator.toString(); - } -} - -function testSourceNode() { - function testConstructor() { - let node: SourceMap.SourceNode; - - node = new SourceMap.SourceNode(); - node = new SourceMap.SourceNode(42, 42, 'foo'); - node = new SourceMap.SourceNode(42, 42, 'foo', 'bar'); - node = new SourceMap.SourceNode(42, 42, 'foo', 'bar', 'slam'); - node = new SourceMap.SourceNode(42, 42, 'foo', ['bar', 'slam']); - } - - function testFromStringWithSourceMap(scm: SourceMap.SourceMapConsumer) { - let node: SourceMap.SourceNode; - - node = SourceMap.SourceNode.fromStringWithSourceMap('foo', scm); - node = SourceMap.SourceNode.fromStringWithSourceMap('foo', scm, 'bar'); - } - - function testAdd(node: SourceMap.SourceNode) { - node.add('foo'); - node.add(new SourceMap.SourceNode()); - node.add([new SourceMap.SourceNode(), 'bar']); - } - - function testPrepend(node: SourceMap.SourceNode) { - node.prepend('foo'); - node.prepend(new SourceMap.SourceNode()); - node.prepend([new SourceMap.SourceNode(), 'bar']); - } - - function testSetSourceContent(node: SourceMap.SourceNode) { - node.setSourceContent('foo', 'bar'); - } - - function testWalk(node: SourceMap.SourceNode) { - let chunk: string; - let mapping: SourceMap.MappedPosition; - - node.walk((c, m) => { chunk = c; mapping = m; }); - } - - function testWalkSourceContents(node: SourceMap.SourceNode) { - let file: string; - let content: string; - - node.walkSourceContents((f, c) => { file = f; content = c; }); - } - - function testJoin(node: SourceMap.SourceNode) { - node = node.join('foo'); - } - - function testReplaceRight(node: SourceMap.SourceNode) { - node = node.replaceRight('foo', 'bar'); - } - - function testToString(node: SourceMap.SourceNode) { - let str: string; - str = node.toString(); - } - - function testToStringWithSourceMap(node: SourceMap.SourceNode, sos: SourceMap.StartOfSourceMap) { - let result: SourceMap.CodeWithSourceMap; - result = node.toStringWithSourceMap(); - result = node.toStringWithSourceMap(sos); - } -} diff --git a/types/source-map/tsconfig.json b/types/source-map/tsconfig.json deleted file mode 100644 index f625e560df..0000000000 --- a/types/source-map/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "source-map-tests.ts" - ] -} \ No newline at end of file diff --git a/types/source-map/tslint.json b/types/source-map/tslint.json deleted file mode 100644 index 7210289f52..0000000000 --- a/types/source-map/tslint.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - // TODO - "prefer-const": false - } -} \ No newline at end of file diff --git a/types/uglify-js/package.json b/types/uglify-js/package.json new file mode 100644 index 0000000000..100334a89f --- /dev/null +++ b/types/uglify-js/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "source-map": "^0.6.1" + } +} diff --git a/types/webpack-sources/package.json b/types/webpack-sources/package.json new file mode 100644 index 0000000000..100334a89f --- /dev/null +++ b/types/webpack-sources/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "source-map": "^0.6.1" + } +}