slimit
slimit copied to clipboard
slimit does not parse javascript "const" expression
Try to parse ««« const theconst = 1; »»» Slimit fails with
SyntaxError: Unexpected token (CONST, u'const') at 1:1 between LexToken(LINE_TERMINATOR,u'\n',1,0) and LexToken(ID,u'theconst',1,7)
Is it bug or a feature?
Although the token was recognised by the lexer no grammar rules actually used it. I've made a patch that adds some, basically assuming that syntactically it works like var except the initialiser is mandatory and it can't be used for iteration.
Also const
is an ES6 concept, which the parser really is only ES5 so a separate ES6 lexer/parser should be created and used instead.
It works in every browser back to IE11... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
I'm surprised this is not working, why not consider it as similar to a "var" statement?
Any update on const
?
const preFormattedBlockNames = {
'api-projects': 'API Projects',
'basic-css': 'Basic CSS',
'basic-html-and-html5': 'Basic HTML and HTML5',
'css-flexbox': 'CSS Flexbox',
'css-grid': 'CSS Grid',
devops: 'DevOps',
es6: 'ES6',
'information-security-with-helmetjs': 'Information Security with HelmetJS',
jquery: 'jQuery',
'json-apis-and-ajax': 'JSON APIs and Ajax',
'mongodb-and-mongoose': 'MongoDB and Mongoose',
'the-dom': 'The DOM',
'apis-and-microservices': 'APIs and Microservices',
'apis-and-microservices-projects': 'APIs and Microservices Projects'
};
const noFormatting = ['and', 'for', 'of', 'the', 'up', 'with'];
exports.blockNameify = function blockNameify(phrase) {
const preFormatted = preFormattedBlockNames[phrase] || '';
if (preFormatted) {
return preFormatted;
}
return phrase
.split('-')
.map(word => {
if (noFormatting.indexOf(word) !== -1) {
return word;
}
if (word === 'javascript') {
return 'JavaScript';
}
return word.charAt(0).toUpperCase() + word.slice(1);
})
.join(' ');
};
Error: Unexpected token (CONST, 'const') at 1:0 between None and LexToken(ID,'preFormattedBlockNames',1,6)