all files / lib/languages/ javascript.js

100% Statements 12/12
100% Branches 0/0
100% Functions 0/0
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                                                                                                     
"use strict";
 
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.javascript = exports.js = undefined;
 
var _clike = require("./clike");
 
var _utils = require("../utils");
 
var _markup = require("./markup");
 
var js = _utils.lang.extend(_clike.clike, {
    keyword: /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,
    number: /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
    // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
    "function": /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i
});
 
_utils.lang.insertBefore(js, "keyword", {
    regex: {
        pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
        lookbehind: true
    },
    _order: ["regex"]
});
 
_utils.lang.insertBefore(js, "class-name", {
    "template-string": {
        pattern: /`(?:\\`|\\?[^`])*`/,
        inside: {
            interpolation: {
                pattern: /\$\{[^}]+\}/,
                inside: {
                    "interpolation-punctuation": {
                        pattern: /^\$\{|\}$/,
                        alias: "punctuation"
                    },
                    _order: ["interpolation-punctuation"]
                }
            },
            string: /[\s\S]+/,
            _order: ["interpolation", "string"]
        }
    },
    _order: ["template-string"]
});
 
_utils.lang.insertAfter(js["template-string"].inside.interpolation.inside, "interpolation-punctuation", _utils.lang.clone(js));
 
_utils.lang.insertBefore(_markup.markup, "tag", {
    "script": {
        pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
        lookbehind: true,
        inside: _utils.lang.clone(js),
        alias: "language-javascript"
    },
    _order: ["script"]
});
 
exports.js = js;
exports.javascript = js;