slimit icon indicating copy to clipboard operation
slimit copied to clipboard

slimit does not parse javascript "const" expression

Open belonesox opened this issue 10 years ago • 5 comments

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?

belonesox avatar Feb 10 '15 16:02 belonesox

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.

fflexo avatar Jan 25 '17 09:01 fflexo

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.

metatoaster avatar Jun 08 '17 04:06 metatoaster

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?

Luke-SF avatar Aug 16 '17 21:08 Luke-SF

Any update on const?

shamoons avatar Jun 19 '19 17:06 shamoons

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)

shamoons avatar Jun 19 '19 17:06 shamoons