Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/dist/
/lib/parser.js
/src/
*.d.ts
File renamed without changes.
28 changes: 14 additions & 14 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Exception from './exception';
import Exception from './exception.js';

function validateClose(open, close) {
close = close.path ? close.path.original : close;
Expand All @@ -17,11 +17,11 @@ export function SourceLocation(source, locInfo) {
this.source = source;
this.start = {
line: locInfo.first_line,
column: locInfo.first_column
column: locInfo.first_column,
};
this.end = {
line: locInfo.last_line,
column: locInfo.last_column
column: locInfo.last_column,
};
}

Expand All @@ -36,7 +36,7 @@ export function id(token) {
export function stripFlags(open, close) {
return {
open: open.charAt(2) === '~',
close: close.charAt(close.length - 3) === '~'
close: close.charAt(close.length - 3) === '~',
};
}

Expand Down Expand Up @@ -93,7 +93,7 @@ export function preparePath(data, sexpr, parts, loc) {
tail,
parts: head ? [head, ...tail] : tail,
original,
loc
loc,
};
}

Expand All @@ -110,7 +110,7 @@ export function prepareMustache(path, params, hash, open, strip, locInfo) {
hash,
escaped,
strip,
loc: this.locInfo(locInfo)
loc: this.locInfo(locInfo),
};
}

Expand All @@ -122,7 +122,7 @@ export function prepareRawBlock(openRawBlock, contents, close, locInfo) {
type: 'Program',
body: contents,
strip: {},
loc: locInfo
loc: locInfo,
};

return {
Expand All @@ -134,7 +134,7 @@ export function prepareRawBlock(openRawBlock, contents, close, locInfo) {
openStrip: {},
inverseStrip: {},
closeStrip: {},
loc: locInfo
loc: locInfo,
};
}

Expand Down Expand Up @@ -188,7 +188,7 @@ export function prepareBlock(
openStrip: openBlock.strip,
inverseStrip,
closeStrip: close && close.strip,
loc: this.locInfo(locInfo)
loc: this.locInfo(locInfo),
};
}

Expand All @@ -203,12 +203,12 @@ export function prepareProgram(statements, loc) {
source: firstLoc.source,
start: {
line: firstLoc.start.line,
column: firstLoc.start.column
column: firstLoc.start.column,
},
end: {
line: lastLoc.end.line,
column: lastLoc.end.column
}
column: lastLoc.end.column,
},
};
}
}
Expand All @@ -217,7 +217,7 @@ export function prepareProgram(statements, loc) {
type: 'Program',
body: statements,
strip: {},
loc: loc
loc: loc,
};
}

Expand All @@ -232,6 +232,6 @@ export function preparePartialBlock(open, program, close, locInfo) {
program,
openStrip: open.strip,
closeStrip: close && close.strip,
loc: this.locInfo(locInfo)
loc: this.locInfo(locInfo),
};
}
12 changes: 6 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { default as Visitor } from './visitor';
export { default as WhitespaceControl } from './whitespace-control';
export { default as parser } from './parser';
export { default as Exception } from './exception';
export { print, PrintVisitor } from './printer';
export { parse, parseWithoutProcessing } from './parse';
export { default as Visitor } from './visitor.js';
export { default as WhitespaceControl } from './whitespace-control.js';
export { default as parser } from './parser.js';
export { default as Exception } from './exception.js';
export { print, PrintVisitor } from './printer.js';
export { parse, parseWithoutProcessing } from './parse.js';
47 changes: 43 additions & 4 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import parser from './parser';
import WhitespaceControl from './whitespace-control';
import * as Helpers from './helpers';
import parser from './parser.js';
import WhitespaceControl from './whitespace-control.js';
import * as Helpers from './helpers.js';

let baseHelpers = {};

Expand All @@ -19,13 +19,52 @@ export function parseWithoutProcessing(input, options) {
parser.yy = baseHelpers;

// Altering the shared object here, but this is ok as parser is a sync operation
parser.yy.locInfo = function(locInfo) {
parser.yy.locInfo = function (locInfo) {
return new Helpers.SourceLocation(options && options.srcName, locInfo);
};

let squareSyntax;

if (typeof options?.syntax?.square === 'function') {
squareSyntax = options.syntax.square;
} else if (options?.syntax?.square === 'node') {
squareSyntax = arrayLiteralNode;
} else {
squareSyntax = 'string';
}

let hashSyntax;

if (typeof options?.syntax?.hash === 'function') {
hashSyntax = options.syntax.hash;
} else {
hashSyntax = hashLiteralNode;
}

parser.yy.syntax = {
square: squareSyntax,
hash: hashSyntax,
};

return parser.parse(input);
}

function arrayLiteralNode(array, loc) {
return {
type: 'ArrayLiteral',
items: array,
loc,
};
}

function hashLiteralNode(hash, loc) {
return {
type: 'HashLiteral',
pairs: hash.pairs,
loc,
};
}

export function parse(input, options) {
let ast = parseWithoutProcessing(input, options);
let strip = new WhitespaceControl(options);
Expand Down
Loading