Skip to content

Commit efe0c6d

Browse files
author
Baptiste Jamin
committed
New Parser Error
1 parent a354866 commit efe0c6d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

index.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
* Or gives undesired access to variables likes document or window? *
99
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1010

11-
var $parseMinErr = function(...args) {
12-
console.error(args);
13-
throw "ERROR";
11+
var $parseMinErr = function(error, template, ...templateArgs) {
12+
var errRegExp = new RegExp('[\\s\\S]*', 'g');
13+
14+
var message = template.replace(/\{\d+\}/g, function(match) {
15+
var index = +match.slice(1, -1);
16+
17+
return templateArgs[index];
18+
});
19+
20+
throw new Error(error + " " + message);
1421
};
1522

1623
var objectValueOf = {}.constructor.prototype.valueOf;
@@ -33,6 +40,12 @@ function getStringValue(name) {
3340
return name + '';
3441
}
3542

43+
var LITERALS = {
44+
'true': true,
45+
'false': false,
46+
'null': null,
47+
'undefined': undefined
48+
};
3649

3750
var OPERATORS = {}
3851

@@ -409,7 +422,9 @@ AST.prototype = {
409422
} else if (this.expect('{')) {
410423
primary = this.object();
411424
} else if (this.selfReferential.hasOwnProperty(this.peek().text)) {
412-
primary = copy(this.selfReferential[this.consume().text]);
425+
primary = Object.assign({}, this.selfReferential[this.consume().text]);
426+
} else if (LITERALS.hasOwnProperty(this.peek().text)) {
427+
primary = { type: AST.Literal, value: LITERALS[this.consume().text]};
413428
} else if (this.peek().identifier) {
414429
primary = this.identifier();
415430
} else if (this.peek().constant) {
@@ -1225,4 +1240,4 @@ function $ParseProvider() {
12251240
}
12261241
}
12271242

1228-
export default $ParseProvider;
1243+
module.exports = $ParseProvider;

0 commit comments

Comments
 (0)