Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify identity source map generator #265

Merged
merged 2 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
"commander": "^2.12.2",
"lines-and-columns": "^1.1.6",
"mz": "^2.7.0",
"pirates": "^3.0.2",
"source-map": "^0.7.3"
"pirates": "^3.0.2"
},
"engines": {
"node": ">=8"
Expand Down
31 changes: 19 additions & 12 deletions src/computeSourceMap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import sourceMap, {RawSourceMap} from "source-map";
import {SourceMapOptions} from "./index";

export interface RawSourceMap {
version: number;
file: string;
sources: Array<string>;
sourceRoot?: string;
sourcesContent?: Array<string>;
mappings: string;
names: Array<string>;
}

/**
* Generate a simple source map indicating that each line maps directly to the original line.
*/
Expand All @@ -9,19 +18,17 @@ export default function computeSourceMap(
filePath: string,
{compiledFilename}: SourceMapOptions,
): RawSourceMap {
const mapGenerator = new sourceMap.SourceMapGenerator({file: compiledFilename});
let numLines = 1;
let mappings = "AAAA";
for (let i = 0; i < code.length; i++) {
if (code[i] === "\n") {
numLines++;
mappings += ";AACA";
}
}
for (let line = 1; line <= numLines; line++) {
mapGenerator.addMapping({
source: filePath,
generated: {line, column: 0},
original: {line, column: 0},
});
}
return mapGenerator.toJSON();
return {
version: 3,
file: compiledFilename || "",
sources: [filePath],
mappings,
names: [],
};
}
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {RawSourceMap} from "source-map";
import CJSImportProcessor from "./CJSImportProcessor";
import computeSourceMap from "./computeSourceMap";
import computeSourceMap, {RawSourceMap} from "./computeSourceMap";
import identifyShadowedGlobals from "./identifyShadowedGlobals";
import NameManager from "./NameManager";
import {parse} from "./parser";
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2665,10 +2665,6 @@ source-map@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"

source-map@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"

spawn-wrap@^1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.4.2.tgz#cff58e73a8224617b6561abdc32586ea0c82248c"
Expand Down