drizzle-cube
Version:
Drizzle ORM-first semantic layer with Cube.js compatibility. Type-safe analytics and dashboards with SQL injection protection.
660 lines (659 loc) • 14.3 kB
JavaScript
const p = "[A-Za-z$_][0-9A-Za-z$_]*", G = [
"as",
// for exports
"in",
"of",
"if",
"for",
"while",
"finally",
"var",
"new",
"function",
"do",
"return",
"void",
"else",
"break",
"catch",
"instanceof",
"with",
"throw",
"case",
"default",
"try",
"switch",
"continue",
"typeof",
"delete",
"let",
"yield",
"const",
"class",
// JS handles these with a special rule
// "get",
// "set",
"debugger",
"async",
"await",
"static",
"import",
"from",
"export",
"extends",
// It's reached stage 3, which is "recommended for implementation":
"using"
], K = [
"true",
"false",
"null",
"undefined",
"NaN",
"Infinity"
], v = [
// Fundamental objects
"Object",
"Function",
"Boolean",
"Symbol",
// numbers and dates
"Math",
"Date",
"Number",
"BigInt",
// text
"String",
"RegExp",
// Indexed collections
"Array",
"Float32Array",
"Float64Array",
"Int8Array",
"Uint8Array",
"Uint8ClampedArray",
"Int16Array",
"Int32Array",
"Uint16Array",
"Uint32Array",
"BigInt64Array",
"BigUint64Array",
// Keyed collections
"Set",
"Map",
"WeakSet",
"WeakMap",
// Structured data
"ArrayBuffer",
"SharedArrayBuffer",
"Atomics",
"DataView",
"JSON",
// Control abstraction objects
"Promise",
"Generator",
"GeneratorFunction",
"AsyncFunction",
// Reflection
"Reflect",
"Proxy",
// Internationalization
"Intl",
// WebAssembly
"WebAssembly"
], L = [
"Error",
"EvalError",
"InternalError",
"RangeError",
"ReferenceError",
"SyntaxError",
"TypeError",
"URIError"
], w = [
"setInterval",
"setTimeout",
"clearInterval",
"clearTimeout",
"require",
"exports",
"eval",
"isFinite",
"isNaN",
"parseFloat",
"parseInt",
"decodeURI",
"decodeURIComponent",
"encodeURI",
"encodeURIComponent",
"escape",
"unescape"
], H = [
"arguments",
"this",
"super",
"console",
"window",
"document",
"localStorage",
"sessionStorage",
"module",
"global"
// Node.js
], J = [].concat(
w,
v,
L
);
function X(e) {
const t = e.regex, B = (a, { after: r }) => {
const l = "</" + a[0].slice(1);
return a.input.indexOf(l, r) !== -1;
}, n = p, A = {
begin: "<>",
end: "</>"
}, h = /<[A-Za-z0-9\\._:-]+\s*\/>/, o = {
begin: /<[A-Za-z0-9\\._:-]+/,
end: /\/[A-Za-z0-9\\._:-]+>|\/>/,
/**
* @param {RegExpMatchArray} match
* @param {CallbackResponse} response
*/
isTrulyOpeningTag: (a, r) => {
const l = a[0].length + a.index, d = a.input[l];
if (
// HTML should not include another raw `<` inside a tag
// nested type?
// `<Array<Array<number>>`, etc.
d === "<" || // the , gives away that this is not HTML
// `<T, A extends keyof T, V>`
d === ","
) {
r.ignoreMatch();
return;
}
d === ">" && (B(a, { after: l }) || r.ignoreMatch());
let u;
const M = a.input.substring(l);
if (u = M.match(/^\s*=/)) {
r.ignoreMatch();
return;
}
if ((u = M.match(/^\s+extends\s+/)) && u.index === 0) {
r.ignoreMatch();
return;
}
}
}, s = {
$pattern: p,
keyword: G,
literal: K,
built_in: J,
"variable.language": H
}, _ = "[0-9](_?[0-9])*", E = `\\.(${_})`, N = "0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*", S = {
className: "number",
variants: [
// DecimalLiteral
{ begin: `(\\b(${N})((${E})|\\.)?|(${E}))[eE][+-]?(${_})\\b` },
{ begin: `\\b(${N})\\b((${E})\\b|\\.)?|(${E})\\b` },
// DecimalBigIntegerLiteral
{ begin: "\\b(0|[1-9](_?[0-9])*)n\\b" },
// NonDecimalIntegerLiteral
{ begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
{ begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
{ begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },
// LegacyOctalIntegerLiteral (does not include underscore separators)
// https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
{ begin: "\\b0[0-7]+n?\\b" }
],
relevance: 0
}, c = {
className: "subst",
begin: "\\$\\{",
end: "\\}",
keywords: s,
contains: []
// defined later
}, m = {
begin: ".?html`",
end: "",
starts: {
end: "`",
returnEnd: !1,
contains: [
e.BACKSLASH_ESCAPE,
c
],
subLanguage: "xml"
}
}, T = {
begin: ".?css`",
end: "",
starts: {
end: "`",
returnEnd: !1,
contains: [
e.BACKSLASH_ESCAPE,
c
],
subLanguage: "css"
}
}, f = {
begin: ".?gql`",
end: "",
starts: {
end: "`",
returnEnd: !1,
contains: [
e.BACKSLASH_ESCAPE,
c
],
subLanguage: "graphql"
}
}, R = {
className: "string",
begin: "`",
end: "`",
contains: [
e.BACKSLASH_ESCAPE,
c
]
}, g = {
className: "comment",
variants: [
e.COMMENT(
/\/\*\*(?!\/)/,
"\\*/",
{
relevance: 0,
contains: [
{
begin: "(?=@[A-Za-z]+)",
relevance: 0,
contains: [
{
className: "doctag",
begin: "@[A-Za-z]+"
},
{
className: "type",
begin: "\\{",
end: "\\}",
excludeEnd: !0,
excludeBegin: !0,
relevance: 0
},
{
className: "variable",
begin: n + "(?=\\s*(-)|$)",
endsParent: !0,
relevance: 0
},
// eat spaces (not newlines) so we can find
// types or variables
{
begin: /(?=[^\n])\s/,
relevance: 0
}
]
}
]
}
),
e.C_BLOCK_COMMENT_MODE,
e.C_LINE_COMMENT_MODE
]
}, y = [
e.APOS_STRING_MODE,
e.QUOTE_STRING_MODE,
m,
T,
f,
R,
// Skip numbers when they are part of a variable name
{ match: /\$\d+/ },
S
// This is intentional:
// See https://github.com/highlightjs/highlight.js/issues/3288
// hljs.REGEXP_MODE
];
c.contains = y.concat({
// we need to pair up {} inside our subst to prevent
// it from ending too early by matching another }
begin: /\{/,
end: /\}/,
keywords: s,
contains: [
"self"
].concat(y)
});
const I = [].concat(g, c.contains), b = I.concat([
// eat recursive parens in sub expressions
{
begin: /(\s*)\(/,
end: /\)/,
keywords: s,
contains: ["self"].concat(I)
}
]), i = {
className: "params",
// convert this to negative lookbehind in v12
begin: /(\s*)\(/,
// to match the parms with
end: /\)/,
excludeBegin: !0,
excludeEnd: !0,
keywords: s,
contains: b
}, x = {
variants: [
// class Car extends vehicle
{
match: [
/class/,
/\s+/,
n,
/\s+/,
/extends/,
/\s+/,
t.concat(n, "(", t.concat(/\./, n), ")*")
],
scope: {
1: "keyword",
3: "title.class",
5: "keyword",
7: "title.class.inherited"
}
},
// class Car
{
match: [
/class/,
/\s+/,
n
],
scope: {
1: "keyword",
3: "title.class"
}
}
]
}, O = {
relevance: 0,
match: t.either(
// Hard coded exceptions
/\bJSON/,
// Float32Array, OutT
/\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,
// CSSFactory, CSSFactoryT
/\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,
// FPs, FPsT
/\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/
// P
// single letters are not highlighted
// BLAH
// this will be flagged as a UPPER_CASE_CONSTANT instead
),
className: "title.class",
keywords: {
_: [
// se we still get relevance credit for JS library classes
...v,
...L
]
}
}, U = {
label: "use_strict",
className: "meta",
relevance: 10,
begin: /^\s*['"]use (strict|asm)['"]/
}, D = {
variants: [
{
match: [
/function/,
/\s+/,
n,
/(?=\s*\()/
]
},
// anonymous function
{
match: [
/function/,
/\s*(?=\()/
]
}
],
className: {
1: "keyword",
3: "title.function"
},
label: "func.def",
contains: [i],
illegal: /%/
}, k = {
relevance: 0,
match: /\b[A-Z][A-Z_0-9]+\b/,
className: "variable.constant"
};
function P(a) {
return t.concat("(?!", a.join("|"), ")");
}
const $ = {
match: t.concat(
/\b/,
P([
...w,
"super",
"import"
].map((a) => `${a}\\s*\\(`)),
n,
t.lookahead(/\s*\(/)
),
className: "title.function",
relevance: 0
}, Z = {
begin: t.concat(/\./, t.lookahead(
t.concat(n, /(?![0-9A-Za-z$_(])/)
)),
end: n,
excludeBegin: !0,
keywords: "prototype",
className: "property",
relevance: 0
}, F = {
match: [
/get|set/,
/\s+/,
n,
/(?=\()/
],
className: {
1: "keyword",
3: "title.function"
},
contains: [
{
// eat to avoid empty params
begin: /\(\)/
},
i
]
}, C = "(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|" + e.UNDERSCORE_IDENT_RE + ")\\s*=>", z = {
match: [
/const|var|let/,
/\s+/,
n,
/\s*/,
/=\s*/,
/(async\s*)?/,
// async is optional
t.lookahead(C)
],
keywords: "async",
className: {
1: "keyword",
3: "title.function"
},
contains: [
i
]
};
return {
name: "JavaScript",
aliases: ["js", "jsx", "mjs", "cjs"],
keywords: s,
// this will be extended by TypeScript
exports: { PARAMS_CONTAINS: b, CLASS_REFERENCE: O },
illegal: /#(?![$_A-z])/,
contains: [
e.SHEBANG({
label: "shebang",
binary: "node",
relevance: 5
}),
U,
e.APOS_STRING_MODE,
e.QUOTE_STRING_MODE,
m,
T,
f,
R,
g,
// Skip numbers when they are part of a variable name
{ match: /\$\d+/ },
S,
O,
{
scope: "attr",
match: n + t.lookahead(":"),
relevance: 0
},
z,
{
// "value" container
begin: "(" + e.RE_STARTERS_RE + "|\\b(case|return|throw)\\b)\\s*",
keywords: "return throw case",
relevance: 0,
contains: [
g,
e.REGEXP_MODE,
{
className: "function",
// we have to count the parens to make sure we actually have the
// correct bounding ( ) before the =>. There could be any number of
// sub-expressions inside also surrounded by parens.
begin: C,
returnBegin: !0,
end: "\\s*=>",
contains: [
{
className: "params",
variants: [
{
begin: e.UNDERSCORE_IDENT_RE,
relevance: 0
},
{
className: null,
begin: /\(\s*\)/,
skip: !0
},
{
begin: /(\s*)\(/,
end: /\)/,
excludeBegin: !0,
excludeEnd: !0,
keywords: s,
contains: b
}
]
}
]
},
{
// could be a comma delimited list of params to a function call
begin: /,/,
relevance: 0
},
{
match: /\s+/,
relevance: 0
},
{
// JSX
variants: [
{ begin: A.begin, end: A.end },
{ match: h },
{
begin: o.begin,
// we carefully check the opening tag to see if it truly
// is a tag and not a false positive
"on:begin": o.isTrulyOpeningTag,
end: o.end
}
],
subLanguage: "xml",
contains: [
{
begin: o.begin,
end: o.end,
skip: !0,
contains: ["self"]
}
]
}
]
},
D,
{
// prevent this from getting swallowed up by function
// since they appear "function like"
beginKeywords: "while if switch catch for"
},
{
// we have to count the parens to make sure we actually have the correct
// bounding ( ). There could be any number of sub-expressions inside
// also surrounded by parens.
begin: "\\b(?!function)" + e.UNDERSCORE_IDENT_RE + "\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",
// end parens
returnBegin: !0,
label: "func.def",
contains: [
i,
e.inherit(e.TITLE_MODE, { begin: n, className: "title.function" })
]
},
// catch ... so it won't trigger the property rule below
{
match: /\.\.\./,
relevance: 0
},
Z,
// hack: prevents detection of keywords in some circumstances
// .keyword()
// $keyword = x
{
match: "\\$" + n,
relevance: 0
},
{
match: [/\bconstructor(?=\s*\()/],
className: { 1: "title.function" },
contains: [i]
},
$,
k,
x,
F,
{
match: /\$[(.]/
// relevance booster for a pattern common to JS libs: `$(something)` and `$.something`
}
]
};
}
export {
X as default
};
//# sourceMappingURL=javascript-DII1YQGr.js.map