Skip to content

Commit

Permalink
Update source-map dependency.
Browse files Browse the repository at this point in the history
This is needed to pick up the fix for mozilla/source-map#273

Closes angular#750
  • Loading branch information
alexeagle committed Feb 19, 2018
1 parent cb1a495 commit ab40524
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"source-map": "^0.5.6",
"source-map": "^0.6.0",
"source-map-support": "^0.5.0"
},
"peerDependencies": {
Expand All @@ -30,7 +30,6 @@
"@types/minimist": "1.2.0",
"@types/mkdirp": "0.5.2",
"@types/node": "6.0.96",
"@types/source-map": "0.5.1",
"@types/source-map-support": "0.4.0",
"chai": "4.1.2",
"chai-diff": "1.0.1",
Expand Down
33 changes: 30 additions & 3 deletions src/source_map_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,32 @@
* found in the LICENSE file at https://angular.io/license
*/

import {BasicSourceMapConsumer, RawSourceMap, SourceMapConsumer, SourceMapGenerator} from 'source-map';
import {RawSourceMap, SourceMapConsumer, SourceMapGenerator} from 'source-map';
import * as ts from './typescript';

/**
* This interface was defined in @types/source-map but is absent from the typings
* distributed in the source-map package.
* Copied from https://unpkg.com/@types/source-map@0.5.2/index.d.ts
* see https://github.com/angular/tsickle/issues/750
*/
export interface BasicSourceMapConsumer extends SourceMapConsumer {
file: string;
sourceRoot: string;
sources: string[];
sourcesContent: string[];
}

/**
* The toJSON method is introduced in
* https://github.com/mozilla/source-map/commit/7c06ac83dd6d75e65f71727184a2d8630a15bf58#diff-7945f6bb445d956794564e098ef20bb3
* However there is a breaking change in 0.7.
* see https://github.com/angular/tsickle/issues/750
*/
export type SourceMapGeneratorToJson = SourceMapGenerator&{
toJSON(): RawSourceMap;
};

/**
* Return a new RegExp object every time we want one because the
* RegExp object has internal state that we don't want to persist
Expand Down Expand Up @@ -87,7 +110,7 @@ export function sourceMapConsumerToGenerator(sourceMapConsumer: SourceMapConsume
export function sourceMapGeneratorToConsumer(
sourceMapGenerator: SourceMapGenerator, fileName?: string,
sourceName?: string): SourceMapConsumer {
const rawSourceMap = sourceMapGenerator.toJSON();
const rawSourceMap = (sourceMapGenerator as SourceMapGeneratorToJson).toJSON();
if (sourceName) {
rawSourceMap.sources = [sourceName];
}
Expand All @@ -102,7 +125,11 @@ export function sourceMapTextToConsumer(sourceMapText: string): BasicSourceMapCo
// IndexedSourceMapConsumer depending on if you pass in a RawSourceMap or a
// RawIndexMap or the string json of either. In this case we're passing in
// the string for a RawSourceMap, so we always get a BasicSourceMapConsumer
return new SourceMapConsumer(sourceMapText) as BasicSourceMapConsumer;
//
// Note, the typings distributed with the library are missing this constructor overload,
// so we must type it as any, see https://github.com/angular/tsickle/issues/750
// tslint:disable-next-line no-any
return new SourceMapConsumer(sourceMapText as any) as BasicSourceMapConsumer;
}

export function sourceMapTextToGenerator(sourceMapText: string): SourceMapGenerator {
Expand Down
4 changes: 2 additions & 2 deletions test/source_map_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {expect} from 'chai';
import {SourceMapConsumer, SourceMapGenerator} from 'source-map';
import * as ts from 'typescript';

import {SourceMapper, SourcePosition} from '../src/source_map_utils';
import {SourceMapGeneratorToJson, SourceMapper, SourcePosition} from '../src/source_map_utils';
import {annotate, AnnotatorHost} from '../src/tsickle';

import {createProgramAndHost} from './test_support';
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('source maps', () => {
const annotated = annotate(
program.getTypeChecker(), program.getSourceFile('input.ts')!,
{pathToModuleName: () => 'input'}, host, program.getCompilerOptions(), sourceMapper);
const rawMap = sourceMapper.sourceMap.toJSON();
const rawMap = (sourceMapper.sourceMap as SourceMapGeneratorToJson).toJSON();
const consumer = new SourceMapConsumer(rawMap);
const lines = annotated.output.split('\n');
// Uncomment to debug contents:
Expand Down
4 changes: 2 additions & 2 deletions test/test_support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {assert, expect} from 'chai';
import * as fs from 'fs';
import * as glob from 'glob';
import * as path from 'path';
import {BasicSourceMapConsumer, SourceMapConsumer} from 'source-map';
import {SourceMapConsumer} from 'source-map';
import * as ts from 'typescript';

import * as cliSupport from '../src/cli_support';
import * as es5processor from '../src/es5processor';
import {toClosureJS} from '../src/main';
import {sourceMapTextToConsumer} from '../src/source_map_utils';
import {BasicSourceMapConsumer, sourceMapTextToConsumer} from '../src/source_map_utils';
import * as tsickle from '../src/tsickle';

/** Base compiler options to be customized and exposed. */
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@
dependencies:
"@types/node" "*"

"@types/source-map@0.5.1":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@types/source-map/-/source-map-0.5.1.tgz#7e74db5d06ab373a712356eebfaea2fad0ea2367"

ansi-gray@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ansi-gray/-/ansi-gray-0.1.1.tgz#2962cf54ec9792c48510a3deb524436861ef7251"
Expand Down

0 comments on commit ab40524

Please sign in to comment.