Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
add startLine option
Browse files Browse the repository at this point in the history
  • Loading branch information
alkhe committed Feb 3, 2017
1 parent 898c4a7 commit c0e579c
Show file tree
Hide file tree
Showing 6 changed files with 471 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Significant diversions are expected to occur in the future such as streaming, EB

- **sourceFilename**: Correlate output AST nodes with their source filename. Useful when generating code and source maps from the ASTs of multiple input files.

- **startLine**: By default, the first line of code parsed is treated as line 1. You can provide a line number to alternatively start with. Useful for integration with other source tools.

- **plugins**: Array containing the plugins that you want to enable.

### Output
Expand Down
4 changes: 4 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export const defaultOptions: {
sourceType: string,
sourceFilename: any,
startLine: number,
allowReturnOutsideFunction: boolean,
allowImportExportEverywhere: boolean,
allowSuperOutsideMethod: boolean,
Expand All @@ -14,6 +15,9 @@ export const defaultOptions: {
sourceType: "script",
// Source filename.
sourceFilename: undefined,
// Line from which to start counting source. Useful for
// integration with other tools.
startLine: 1,
// When enabled, a return at the top level is not considered an
// error.
allowReturnOutsideFunction: false,
Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class State {
this.commentStack = [];

this.pos = this.lineStart = 0;
this.curLine = 1;
this.curLine = options.startLine;

this.type = tt.eof;
this.value = null;
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/core/categorized/startline-specified/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
call(1);
run(2);
Loading

0 comments on commit c0e579c

Please sign in to comment.