Merge pull request #3323 from divmain/master

Source-map support for multiple input source files
This commit is contained in:
Amjad Masad
2016-03-07 11:57:59 -08:00
11 changed files with 208 additions and 7 deletions

View File

@@ -3,6 +3,7 @@
export const defaultOptions: {
sourceType: string,
sourceFilename: any,
allowReturnOutsideFunction: boolean,
allowImportExportEverywhere: boolean,
allowSuperOutsideMethod: boolean,
@@ -11,6 +12,8 @@ export const defaultOptions: {
} = {
// Source type ("script" or "module") for different semantics
sourceType: "script",
// Source filename.
sourceFilename: undefined,
// When enabled, a return at the top level is not considered an
// error.
allowReturnOutsideFunction: false,

View File

@@ -14,6 +14,7 @@ export default class Parser extends Tokenizer {
this.isReservedWord = reservedWords[6];
this.input = input;
this.plugins = this.loadPlugins(this.options.plugins);
this.filename = options.sourceFilename;
// If enabled, skip leading hashbang line.
if (this.state.pos === 0 && this.input[0] === "#" && this.input[1] === "!") {

View File

@@ -6,11 +6,12 @@ import { SourceLocation } from "../util/location";
const pp = Parser.prototype;
class Node {
constructor(pos?: number, loc?: SourceLocation) {
constructor(pos?: number, loc?: SourceLocation, filename?: string) {
this.type = "";
this.start = pos;
this.end = 0;
this.loc = new SourceLocation(loc);
if (filename) this.loc.filename = filename;
}
type: string;
@@ -26,11 +27,11 @@ class Node {
}
pp.startNode = function () {
return new Node(this.state.start, this.state.startLoc);
return new Node(this.state.start, this.state.startLoc, this.filename);
};
pp.startNodeAt = function (pos, loc) {
return new Node(pos, loc);
return new Node(pos, loc, this.filename);
};
function finishNodeAt(node, type, pos, loc) {