UNPKG

shiki

Version:
1,631 lines (1,624 loc) 92.1 kB
'use strict'; var vscodeOniguruma = require('vscode-oniguruma'); var vscodeTextmate = require('vscode-textmate'); const themes = [ "css-variables", "dark-plus", "dracula-soft", "dracula", "github-dark-dimmed", "github-dark", "github-light", "hc_light", "light-plus", "material-theme-darker", "material-theme-lighter", "material-theme-ocean", "material-theme-palenight", "material-theme", "min-dark", "min-light", "monokai", "nord", "one-dark-pro", "poimandres", "rose-pine-dawn", "rose-pine-moon", "rose-pine", "slack-dark", "slack-ochin", "solarized-dark", "solarized-light", "vitesse-dark", "vitesse-light" ]; const languages = [ { id: "abap", scopeName: "source.abap", path: "abap.tmLanguage.json", samplePath: "abap.sample" }, { id: "actionscript-3", scopeName: "source.actionscript.3", path: "actionscript-3.tmLanguage.json", samplePath: "actionscript-3.sample" }, { id: "ada", scopeName: "source.ada", path: "ada.tmLanguage.json", samplePath: "ada.sample" }, { id: "apache", scopeName: "source.apacheconf", path: "apache.tmLanguage.json" }, { id: "apex", scopeName: "source.apex", path: "apex.tmLanguage.json", samplePath: "apex.sample" }, { id: "apl", scopeName: "source.apl", path: "apl.tmLanguage.json", embeddedLangs: ["html", "xml", "css", "javascript", "json"] }, { id: "applescript", scopeName: "source.applescript", path: "applescript.tmLanguage.json", samplePath: "applescript.sample" }, { id: "ara", scopeName: "source.ara", path: "ara.tmLanguage.json", samplePath: "ara.sample" }, { id: "asm", scopeName: "source.asm.x86_64", path: "asm.tmLanguage.json", samplePath: "asm.sample" }, { id: "astro", scopeName: "source.astro", path: "astro.tmLanguage.json", samplePath: "astro.sample", embeddedLangs: ["json", "javascript", "typescript", "stylus", "sass", "css", "scss", "less", "postcss", "tsx"] }, { id: "awk", scopeName: "source.awk", path: "awk.tmLanguage.json", samplePath: "awk.sample" }, { id: "ballerina", scopeName: "source.ballerina", path: "ballerina.tmLanguage.json", samplePath: "ballerina.sample" }, { id: "bat", scopeName: "source.batchfile", path: "bat.tmLanguage.json", samplePath: "bat.sample", aliases: ["batch"] }, { id: "berry", scopeName: "source.berry", path: "berry.tmLanguage.json", samplePath: "berry.sample", aliases: ["be"] }, { id: "bibtex", scopeName: "text.bibtex", path: "bibtex.tmLanguage.json" }, { id: "bicep", scopeName: "source.bicep", path: "bicep.tmLanguage.json", samplePath: "bicep.sample" }, { id: "blade", scopeName: "text.html.php.blade", path: "blade.tmLanguage.json", samplePath: "blade.sample", embeddedLangs: ["html", "xml", "sql", "javascript", "json", "css"] }, { id: "c", scopeName: "source.c", path: "c.tmLanguage.json", samplePath: "c.sample" }, { id: "cadence", scopeName: "source.cadence", path: "cadence.tmLanguage.json", samplePath: "cadence.sample", aliases: ["cdc"] }, { id: "clarity", scopeName: "source.clar", path: "clarity.tmLanguage.json", samplePath: "clarity.sample" }, { id: "clojure", scopeName: "source.clojure", path: "clojure.tmLanguage.json", samplePath: "clojure.sample", aliases: ["clj"] }, { id: "cmake", scopeName: "source.cmake", path: "cmake.tmLanguage.json", samplePath: "cmake.sample" }, { id: "cobol", scopeName: "source.cobol", path: "cobol.tmLanguage.json", samplePath: "cobol.sample", embeddedLangs: ["sql", "html", "java"] }, { id: "codeql", scopeName: "source.ql", path: "codeql.tmLanguage.json", samplePath: "codeql.sample", aliases: ["ql"], embeddedLangs: ["markdown"] }, { id: "coffee", scopeName: "source.coffee", path: "coffee.tmLanguage.json", samplePath: "coffee.sample", embeddedLangs: ["javascript"] }, { id: "cpp", scopeName: "source.cpp", path: "cpp.tmLanguage.json", samplePath: "cpp.sample", embeddedLangs: ["glsl", "sql"] }, { id: "crystal", scopeName: "source.crystal", path: "crystal.tmLanguage.json", samplePath: "crystal.sample", embeddedLangs: ["html", "sql", "css", "c", "javascript", "shellscript"] }, { id: "csharp", scopeName: "source.cs", path: "csharp.tmLanguage.json", samplePath: "csharp.sample", aliases: ["c#", "cs"] }, { id: "css", scopeName: "source.css", path: "css.tmLanguage.json", samplePath: "css.sample" }, { id: "cue", scopeName: "source.cue", path: "cue.tmLanguage.json", samplePath: "cue.sample" }, { id: "d", scopeName: "source.d", path: "d.tmLanguage.json", samplePath: "d.sample" }, { id: "dart", scopeName: "source.dart", path: "dart.tmLanguage.json", samplePath: "dart.sample" }, { id: "dax", scopeName: "source.dax", path: "dax.tmLanguage.json", samplePath: "dax.sample" }, { id: "diff", scopeName: "source.diff", path: "diff.tmLanguage.json", samplePath: "diff.sample" }, { id: "docker", scopeName: "source.dockerfile", path: "docker.tmLanguage.json", samplePath: "docker.sample", aliases: ["dockerfile"] }, { id: "dream-maker", scopeName: "source.dm", path: "dream-maker.tmLanguage.json" }, { id: "elixir", scopeName: "source.elixir", path: "elixir.tmLanguage.json", samplePath: "elixir.sample", embeddedLangs: ["html"] }, { id: "elm", scopeName: "source.elm", path: "elm.tmLanguage.json", samplePath: "elm.sample", embeddedLangs: ["glsl"] }, { id: "erb", scopeName: "text.html.erb", path: "erb.tmLanguage.json", samplePath: "erb.sample", embeddedLangs: ["html", "ruby"] }, { id: "erlang", scopeName: "source.erlang", path: "erlang.tmLanguage.json", samplePath: "erlang.sample", aliases: ["erl"] }, { id: "fish", scopeName: "source.fish", path: "fish.tmLanguage.json", samplePath: "fish.sample" }, { id: "fsharp", scopeName: "source.fsharp", path: "fsharp.tmLanguage.json", samplePath: "fsharp.sample", aliases: ["f#", "fs"], embeddedLangs: ["markdown"] }, { id: "gdresource", scopeName: "source.gdresource", path: "gdresource.tmLanguage.json", samplePath: "gdresource.sample", embeddedLangs: ["gdshader", "gdscript"] }, { id: "gdscript", scopeName: "source.gdscript", path: "gdscript.tmLanguage.json", samplePath: "gdscript.sample" }, { id: "gdshader", scopeName: "source.gdshader", path: "gdshader.tmLanguage.json", samplePath: "gdshader.sample" }, { id: "gherkin", scopeName: "text.gherkin.feature", path: "gherkin.tmLanguage.json" }, { id: "git-commit", scopeName: "text.git-commit", path: "git-commit.tmLanguage.json", embeddedLangs: ["diff"] }, { id: "git-rebase", scopeName: "text.git-rebase", path: "git-rebase.tmLanguage.json", embeddedLangs: ["shellscript"] }, { id: "glsl", scopeName: "source.glsl", path: "glsl.tmLanguage.json", samplePath: "glsl.sample", embeddedLangs: ["c"] }, { id: "gnuplot", scopeName: "source.gnuplot", path: "gnuplot.tmLanguage.json" }, { id: "go", scopeName: "source.go", path: "go.tmLanguage.json", samplePath: "go.sample" }, { id: "graphql", scopeName: "source.graphql", path: "graphql.tmLanguage.json", embeddedLangs: ["javascript", "typescript", "jsx", "tsx"] }, { id: "groovy", scopeName: "source.groovy", path: "groovy.tmLanguage.json" }, { id: "hack", scopeName: "source.hack", path: "hack.tmLanguage.json", embeddedLangs: ["html", "sql"] }, { id: "haml", scopeName: "text.haml", path: "haml.tmLanguage.json", embeddedLangs: ["ruby", "javascript", "sass", "coffee", "markdown", "css"] }, { id: "handlebars", scopeName: "text.html.handlebars", path: "handlebars.tmLanguage.json", aliases: ["hbs"], embeddedLangs: ["html", "css", "javascript", "yaml"] }, { id: "haskell", scopeName: "source.haskell", path: "haskell.tmLanguage.json", aliases: ["hs"] }, { id: "hcl", scopeName: "source.hcl", path: "hcl.tmLanguage.json", samplePath: "hcl.sample" }, { id: "hlsl", scopeName: "source.hlsl", path: "hlsl.tmLanguage.json" }, { id: "html", scopeName: "text.html.basic", path: "html.tmLanguage.json", samplePath: "html.sample", embeddedLangs: ["javascript", "css"] }, { id: "http", scopeName: "source.http", path: "http.tmLanguage.json", samplePath: "http.sample", embeddedLangs: ["shellscript", "json", "xml", "graphql"] }, { id: "imba", scopeName: "source.imba", path: "imba.tmLanguage.json", samplePath: "imba.sample" }, { id: "ini", scopeName: "source.ini", path: "ini.tmLanguage.json", aliases: ["properties"] }, { id: "java", scopeName: "source.java", path: "java.tmLanguage.json", samplePath: "java.sample" }, { id: "javascript", scopeName: "source.js", path: "javascript.tmLanguage.json", samplePath: "javascript.sample", aliases: ["js"] }, { id: "jinja-html", scopeName: "text.html.jinja", path: "jinja-html.tmLanguage.json", embeddedLangs: ["html"] }, { id: "jison", scopeName: "source.jison", path: "jison.tmLanguage.json", samplePath: "jison.sample", embeddedLangs: ["javascript"] }, { id: "json", scopeName: "source.json", path: "json.tmLanguage.json" }, { id: "json5", scopeName: "source.json5", path: "json5.tmLanguage.json", samplePath: "json5.sample" }, { id: "jsonc", scopeName: "source.json.comments", path: "jsonc.tmLanguage.json" }, { id: "jsonnet", scopeName: "source.jsonnet", path: "jsonnet.tmLanguage.json" }, { id: "jssm", scopeName: "source.jssm", path: "jssm.tmLanguage.json", samplePath: "jssm.sample", aliases: ["fsl"] }, { id: "jsx", scopeName: "source.js.jsx", path: "jsx.tmLanguage.json" }, { id: "julia", scopeName: "source.julia", path: "julia.tmLanguage.json", embeddedLangs: ["cpp", "python", "javascript", "r", "sql"] }, { id: "kotlin", scopeName: "source.kotlin", path: "kotlin.tmLanguage.json", samplePath: "kotlin.sample" }, { id: "kusto", scopeName: "source.kusto", path: "kusto.tmLanguage.json", samplePath: "kusto.sample", aliases: ["kql"] }, { id: "latex", scopeName: "text.tex.latex", path: "latex.tmLanguage.json", embeddedLangs: ["tex", "css", "haskell", "html", "xml", "java", "lua", "julia", "ruby", "javascript", "typescript", "python", "yaml", "rust", "scala", "gnuplot"] }, { id: "less", scopeName: "source.css.less", path: "less.tmLanguage.json", embeddedLangs: ["css"] }, { id: "liquid", scopeName: "text.html.liquid", path: "liquid.tmLanguage.json", samplePath: "liquid.sample", embeddedLangs: ["html", "css", "json", "javascript"] }, { id: "lisp", scopeName: "source.lisp", path: "lisp.tmLanguage.json" }, { id: "logo", scopeName: "source.logo", path: "logo.tmLanguage.json" }, { id: "lua", scopeName: "source.lua", path: "lua.tmLanguage.json", embeddedLangs: ["c"] }, { id: "make", scopeName: "source.makefile", path: "make.tmLanguage.json", aliases: ["makefile"] }, { id: "markdown", scopeName: "text.html.markdown", path: "markdown.tmLanguage.json", aliases: ["md"], embeddedLangs: ["css", "html", "ini", "java", "lua", "make", "perl", "r", "ruby", "php", "sql", "vb", "xml", "xsl", "yaml", "bat", "clojure", "coffee", "c", "cpp", "diff", "docker", "git-commit", "git-rebase", "go", "groovy", "pug", "javascript", "json", "jsonc", "less", "objective-c", "swift", "scss", "raku", "powershell", "python", "julia", "rust", "scala", "shellscript", "typescript", "tsx", "csharp", "fsharp", "dart", "handlebars", "erlang", "elixir", "latex", "bibtex"] }, { id: "marko", scopeName: "text.marko", path: "marko.tmLanguage.json", embeddedLangs: ["css", "less", "scss", "javascript"] }, { id: "matlab", scopeName: "source.matlab", path: "matlab.tmLanguage.json" }, { id: "mdx", scopeName: "source.mdx", path: "mdx.tmLanguage.json", embeddedLangs: ["tsx", "toml", "yaml", "c", "clojure", "coffee", "cpp", "csharp", "css", "diff", "docker", "elixir", "elm", "erlang", "go", "graphql", "haskell", "html", "ini", "java", "javascript", "json", "julia", "kotlin", "less", "lua", "make", "markdown", "objective-c", "perl", "python", "r", "ruby", "rust", "scala", "scss", "shellscript", "sql", "xml", "swift", "typescript"] }, { id: "mermaid", scopeName: "source.mermaid", path: "mermaid.tmLanguage.json" }, { id: "nginx", scopeName: "source.nginx", path: "nginx.tmLanguage.json", embeddedLangs: ["lua"] }, { id: "nim", scopeName: "source.nim", path: "nim.tmLanguage.json", embeddedLangs: ["c", "html", "xml", "javascript", "css", "glsl", "markdown"] }, { id: "nix", scopeName: "source.nix", path: "nix.tmLanguage.json" }, { id: "objective-c", scopeName: "source.objc", path: "objective-c.tmLanguage.json", aliases: ["objc"] }, { id: "objective-cpp", scopeName: "source.objcpp", path: "objective-cpp.tmLanguage.json" }, { id: "ocaml", scopeName: "source.ocaml", path: "ocaml.tmLanguage.json" }, { id: "pascal", scopeName: "source.pascal", path: "pascal.tmLanguage.json" }, { id: "perl", scopeName: "source.perl", path: "perl.tmLanguage.json", embeddedLangs: ["html", "xml", "css", "javascript", "sql"] }, { id: "php", scopeName: "source.php", path: "php.tmLanguage.json", embeddedLangs: ["html", "xml", "sql", "javascript", "json", "css"] }, { id: "plsql", scopeName: "source.plsql.oracle", path: "plsql.tmLanguage.json" }, { id: "postcss", scopeName: "source.css.postcss", path: "postcss.tmLanguage.json" }, { id: "powerquery", scopeName: "source.powerquery", path: "powerquery.tmLanguage.json", samplePath: "powerquery.sample" }, { id: "powershell", scopeName: "source.powershell", path: "powershell.tmLanguage.json", aliases: ["ps", "ps1"] }, { id: "prisma", scopeName: "source.prisma", path: "prisma.tmLanguage.json", samplePath: "prisma.sample" }, { id: "prolog", scopeName: "source.prolog", path: "prolog.tmLanguage.json" }, { id: "proto", scopeName: "source.proto", path: "proto.tmLanguage.json", samplePath: "proto.sample" }, { id: "pug", scopeName: "text.pug", path: "pug.tmLanguage.json", aliases: ["jade"], embeddedLangs: ["javascript", "css", "sass", "scss", "stylus", "coffee", "html"] }, { id: "puppet", scopeName: "source.puppet", path: "puppet.tmLanguage.json" }, { id: "purescript", scopeName: "source.purescript", path: "purescript.tmLanguage.json" }, { id: "python", scopeName: "source.python", path: "python.tmLanguage.json", samplePath: "python.sample", aliases: ["py"] }, { id: "r", scopeName: "source.r", path: "r.tmLanguage.json" }, { id: "raku", scopeName: "source.perl.6", path: "raku.tmLanguage.json", aliases: ["perl6"] }, { id: "razor", scopeName: "text.aspnetcorerazor", path: "razor.tmLanguage.json", embeddedLangs: ["html", "csharp"] }, { id: "reg", scopeName: "source.reg", path: "reg.tmLanguage.json", samplePath: "reg.sample" }, { id: "rel", scopeName: "source.rel", path: "rel.tmLanguage.json", samplePath: "rel.sample" }, { id: "riscv", scopeName: "source.riscv", path: "riscv.tmLanguage.json" }, { id: "rst", scopeName: "source.rst", path: "rst.tmLanguage.json", embeddedLangs: ["cpp", "python", "javascript", "shellscript", "yaml", "cmake", "ruby"] }, { id: "ruby", scopeName: "source.ruby", path: "ruby.tmLanguage.json", samplePath: "ruby.sample", aliases: ["rb"], embeddedLangs: ["html", "xml", "sql", "css", "c", "javascript", "shellscript", "lua"] }, { id: "rust", scopeName: "source.rust", path: "rust.tmLanguage.json", aliases: ["rs"] }, { id: "sas", scopeName: "source.sas", path: "sas.tmLanguage.json", embeddedLangs: ["sql"] }, { id: "sass", scopeName: "source.sass", path: "sass.tmLanguage.json" }, { id: "scala", scopeName: "source.scala", path: "scala.tmLanguage.json" }, { id: "scheme", scopeName: "source.scheme", path: "scheme.tmLanguage.json" }, { id: "scss", scopeName: "source.css.scss", path: "scss.tmLanguage.json", embeddedLangs: ["css"] }, { id: "shaderlab", scopeName: "source.shaderlab", path: "shaderlab.tmLanguage.json", aliases: ["shader"], embeddedLangs: ["hlsl"] }, { id: "shellscript", scopeName: "source.shell", path: "shellscript.tmLanguage.json", aliases: ["bash", "console", "sh", "shell", "zsh"] }, { id: "smalltalk", scopeName: "source.smalltalk", path: "smalltalk.tmLanguage.json" }, { id: "solidity", scopeName: "source.solidity", path: "solidity.tmLanguage.json" }, { id: "sparql", scopeName: "source.sparql", path: "sparql.tmLanguage.json", samplePath: "sparql.sample", embeddedLangs: ["turtle"] }, { id: "sql", scopeName: "source.sql", path: "sql.tmLanguage.json" }, { id: "ssh-config", scopeName: "source.ssh-config", path: "ssh-config.tmLanguage.json" }, { id: "stata", scopeName: "source.stata", path: "stata.tmLanguage.json", samplePath: "stata.sample", embeddedLangs: ["sql"] }, { id: "stylus", scopeName: "source.stylus", path: "stylus.tmLanguage.json", aliases: ["styl"] }, { id: "svelte", scopeName: "source.svelte", path: "svelte.tmLanguage.json", embeddedLangs: ["javascript", "typescript", "coffee", "stylus", "sass", "css", "scss", "less", "postcss", "pug", "markdown"] }, { id: "swift", scopeName: "source.swift", path: "swift.tmLanguage.json" }, { id: "system-verilog", scopeName: "source.systemverilog", path: "system-verilog.tmLanguage.json" }, { id: "tasl", scopeName: "source.tasl", path: "tasl.tmLanguage.json", samplePath: "tasl.sample" }, { id: "tcl", scopeName: "source.tcl", path: "tcl.tmLanguage.json" }, { id: "tex", scopeName: "text.tex", path: "tex.tmLanguage.json", embeddedLangs: ["r"] }, { id: "toml", scopeName: "source.toml", path: "toml.tmLanguage.json" }, { id: "tsx", scopeName: "source.tsx", path: "tsx.tmLanguage.json", samplePath: "tsx.sample" }, { id: "turtle", scopeName: "source.turtle", path: "turtle.tmLanguage.json", samplePath: "turtle.sample" }, { id: "twig", scopeName: "text.html.twig", path: "twig.tmLanguage.json", embeddedLangs: ["css", "javascript", "php", "python", "ruby"] }, { id: "typescript", scopeName: "source.ts", path: "typescript.tmLanguage.json", aliases: ["ts"] }, { id: "v", scopeName: "source.v", path: "v.tmLanguage.json", samplePath: "v.sample" }, { id: "vb", scopeName: "source.asp.vb.net", path: "vb.tmLanguage.json", aliases: ["cmd"] }, { id: "verilog", scopeName: "source.verilog", path: "verilog.tmLanguage.json" }, { id: "vhdl", scopeName: "source.vhdl", path: "vhdl.tmLanguage.json" }, { id: "viml", scopeName: "source.viml", path: "viml.tmLanguage.json", aliases: ["vim", "vimscript"] }, { id: "vue-html", scopeName: "text.html.vue-html", path: "vue-html.tmLanguage.json", embeddedLangs: ["vue", "javascript"] }, { id: "vue", scopeName: "source.vue", path: "vue.tmLanguage.json", embeddedLangs: ["html", "markdown", "pug", "stylus", "sass", "css", "scss", "less", "javascript", "typescript", "jsx", "tsx", "json", "jsonc", "json5", "yaml", "toml", "graphql"] }, { id: "wasm", scopeName: "source.wat", path: "wasm.tmLanguage.json" }, { id: "wenyan", scopeName: "source.wenyan", path: "wenyan.tmLanguage.json", aliases: ["\u6587\u8A00"] }, { id: "wgsl", scopeName: "source.wgsl", path: "wgsl.tmLanguage.json", samplePath: "wgsl.sample" }, { id: "wolfram", scopeName: "source.wolfram", path: "wolfram.tmLanguage.json", samplePath: "wolfram.sample" }, { id: "xml", scopeName: "text.xml", path: "xml.tmLanguage.json", embeddedLangs: ["java"] }, { id: "xsl", scopeName: "text.xml.xsl", path: "xsl.tmLanguage.json", embeddedLangs: ["xml"] }, { id: "yaml", scopeName: "source.yaml", path: "yaml.tmLanguage.json", aliases: ["yml"] }, { id: "zenscript", scopeName: "source.zenscript", path: "zenscript.tmLanguage.json", samplePath: "zenscript.sample" } ]; var FontStyle = /* @__PURE__ */ ((FontStyle2) => { FontStyle2[FontStyle2["NotSet"] = -1] = "NotSet"; FontStyle2[FontStyle2["None"] = 0] = "None"; FontStyle2[FontStyle2["Italic"] = 1] = "Italic"; FontStyle2[FontStyle2["Bold"] = 2] = "Bold"; FontStyle2[FontStyle2["Underline"] = 4] = "Underline"; return FontStyle2; })(FontStyle || {}); class StackElementMetadata { static toBinaryStr(metadata) { let r = metadata.toString(2); while (r.length < 32) { r = "0" + r; } return r; } static printMetadata(metadata) { let languageId = StackElementMetadata.getLanguageId(metadata); let tokenType = StackElementMetadata.getTokenType(metadata); let fontStyle = StackElementMetadata.getFontStyle(metadata); let foreground = StackElementMetadata.getForeground(metadata); let background = StackElementMetadata.getBackground(metadata); console.log({ languageId, tokenType, fontStyle, foreground, background }); } static getLanguageId(metadata) { return (metadata & 255 /* LANGUAGEID_MASK */) >>> 0 /* LANGUAGEID_OFFSET */; } static getTokenType(metadata) { return (metadata & 768 /* TOKEN_TYPE_MASK */) >>> 8 /* TOKEN_TYPE_OFFSET */; } static getFontStyle(metadata) { return (metadata & 14336 /* FONT_STYLE_MASK */) >>> 11 /* FONT_STYLE_OFFSET */; } static getForeground(metadata) { return (metadata & 8372224 /* FOREGROUND_MASK */) >>> 15 /* FOREGROUND_OFFSET */; } static getBackground(metadata) { return (metadata & 4286578688 /* BACKGROUND_MASK */) >>> 24 /* BACKGROUND_OFFSET */; } static containsBalancedBrackets(metadata) { return (metadata & 1024 /* BALANCED_BRACKETS_MASK */) !== 0; } static set(metadata, languageId, tokenType, fontStyle, foreground, background) { let _languageId = StackElementMetadata.getLanguageId(metadata); let _tokenType = StackElementMetadata.getTokenType(metadata); let _fontStyle = StackElementMetadata.getFontStyle(metadata); let _foreground = StackElementMetadata.getForeground(metadata); let _background = StackElementMetadata.getBackground(metadata); let _containsBalancedBracketsBit = StackElementMetadata.containsBalancedBrackets( metadata ) ? 1 : 0; if (languageId !== 0) { _languageId = languageId; } if (tokenType !== 0 /* Other */) { _tokenType = tokenType === 8 /* MetaEmbedded */ ? 0 /* Other */ : tokenType; } if (fontStyle !== -1 /* NotSet */) { _fontStyle = fontStyle; } if (foreground !== 0) { _foreground = foreground; } if (background !== 0) { _background = background; } return (_languageId << 0 /* LANGUAGEID_OFFSET */ | _tokenType << 8 /* TOKEN_TYPE_OFFSET */ | _fontStyle << 11 /* FONT_STYLE_OFFSET */ | _containsBalancedBracketsBit << 10 /* BALANCED_BRACKETS_OFFSET */ | _foreground << 15 /* FOREGROUND_OFFSET */ | _background << 24 /* BACKGROUND_OFFSET */) >>> 0; } } function trimEndSlash(str) { if (str.endsWith("/") || str.endsWith("\\")) return str.slice(0, -1); return str; } function trimStartDot(str) { if (str.startsWith("./")) return str.slice(2); return str; } function dirpathparts(str) { const parts = str.split(/[\/\\]/g); return parts.slice(0, parts.length - 1); } function join(...parts) { return parts.map(trimEndSlash).map(trimStartDot).join("/"); } function groupBy(elements, keyGetter) { const map = /* @__PURE__ */ new Map(); for (const element of elements) { const key = keyGetter(element); if (map.has(key)) { const group = map.get(key); group.push(element); } else { map.set(key, [element]); } } return map; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Creates a JSON scanner on the given text. * If ignoreTrivia is set, whitespaces or comments are ignored. */ function createScanner(text, ignoreTrivia = false) { const len = text.length; let pos = 0, value = '', tokenOffset = 0, token = 16 /* SyntaxKind.Unknown */, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0 /* ScanError.None */; function scanHexDigits(count, exact) { let digits = 0; let value = 0; while (digits < count || !exact) { let ch = text.charCodeAt(pos); if (ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */) { value = value * 16 + ch - 48 /* CharacterCodes._0 */; } else if (ch >= 65 /* CharacterCodes.A */ && ch <= 70 /* CharacterCodes.F */) { value = value * 16 + ch - 65 /* CharacterCodes.A */ + 10; } else if (ch >= 97 /* CharacterCodes.a */ && ch <= 102 /* CharacterCodes.f */) { value = value * 16 + ch - 97 /* CharacterCodes.a */ + 10; } else { break; } pos++; digits++; } if (digits < count) { value = -1; } return value; } function setPosition(newPosition) { pos = newPosition; value = ''; tokenOffset = 0; token = 16 /* SyntaxKind.Unknown */; scanError = 0 /* ScanError.None */; } function scanNumber() { let start = pos; if (text.charCodeAt(pos) === 48 /* CharacterCodes._0 */) { pos++; } else { pos++; while (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; } } if (pos < text.length && text.charCodeAt(pos) === 46 /* CharacterCodes.dot */) { pos++; if (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; while (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; } } else { scanError = 3 /* ScanError.UnexpectedEndOfNumber */; return text.substring(start, pos); } } let end = pos; if (pos < text.length && (text.charCodeAt(pos) === 69 /* CharacterCodes.E */ || text.charCodeAt(pos) === 101 /* CharacterCodes.e */)) { pos++; if (pos < text.length && text.charCodeAt(pos) === 43 /* CharacterCodes.plus */ || text.charCodeAt(pos) === 45 /* CharacterCodes.minus */) { pos++; } if (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; while (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; } end = pos; } else { scanError = 3 /* ScanError.UnexpectedEndOfNumber */; } } return text.substring(start, end); } function scanString() { let result = '', start = pos; while (true) { if (pos >= len) { result += text.substring(start, pos); scanError = 2 /* ScanError.UnexpectedEndOfString */; break; } const ch = text.charCodeAt(pos); if (ch === 34 /* CharacterCodes.doubleQuote */) { result += text.substring(start, pos); pos++; break; } if (ch === 92 /* CharacterCodes.backslash */) { result += text.substring(start, pos); pos++; if (pos >= len) { scanError = 2 /* ScanError.UnexpectedEndOfString */; break; } const ch2 = text.charCodeAt(pos++); switch (ch2) { case 34 /* CharacterCodes.doubleQuote */: result += '\"'; break; case 92 /* CharacterCodes.backslash */: result += '\\'; break; case 47 /* CharacterCodes.slash */: result += '/'; break; case 98 /* CharacterCodes.b */: result += '\b'; break; case 102 /* CharacterCodes.f */: result += '\f'; break; case 110 /* CharacterCodes.n */: result += '\n'; break; case 114 /* CharacterCodes.r */: result += '\r'; break; case 116 /* CharacterCodes.t */: result += '\t'; break; case 117 /* CharacterCodes.u */: const ch3 = scanHexDigits(4, true); if (ch3 >= 0) { result += String.fromCharCode(ch3); } else { scanError = 4 /* ScanError.InvalidUnicode */; } break; default: scanError = 5 /* ScanError.InvalidEscapeCharacter */; } start = pos; continue; } if (ch >= 0 && ch <= 0x1f) { if (isLineBreak(ch)) { result += text.substring(start, pos); scanError = 2 /* ScanError.UnexpectedEndOfString */; break; } else { scanError = 6 /* ScanError.InvalidCharacter */; // mark as error but continue with string } } pos++; } return result; } function scanNext() { value = ''; scanError = 0 /* ScanError.None */; tokenOffset = pos; lineStartOffset = lineNumber; prevTokenLineStartOffset = tokenLineStartOffset; if (pos >= len) { // at the end tokenOffset = len; return token = 17 /* SyntaxKind.EOF */; } let code = text.charCodeAt(pos); // trivia: whitespace if (isWhiteSpace(code)) { do { pos++; value += String.fromCharCode(code); code = text.charCodeAt(pos); } while (isWhiteSpace(code)); return token = 15 /* SyntaxKind.Trivia */; } // trivia: newlines if (isLineBreak(code)) { pos++; value += String.fromCharCode(code); if (code === 13 /* CharacterCodes.carriageReturn */ && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) { pos++; value += '\n'; } lineNumber++; tokenLineStartOffset = pos; return token = 14 /* SyntaxKind.LineBreakTrivia */; } switch (code) { // tokens: []{}:, case 123 /* CharacterCodes.openBrace */: pos++; return token = 1 /* SyntaxKind.OpenBraceToken */; case 125 /* CharacterCodes.closeBrace */: pos++; return token = 2 /* SyntaxKind.CloseBraceToken */; case 91 /* CharacterCodes.openBracket */: pos++; return token = 3 /* SyntaxKind.OpenBracketToken */; case 93 /* CharacterCodes.closeBracket */: pos++; return token = 4 /* SyntaxKind.CloseBracketToken */; case 58 /* CharacterCodes.colon */: pos++; return token = 6 /* SyntaxKind.ColonToken */; case 44 /* CharacterCodes.comma */: pos++; return token = 5 /* SyntaxKind.CommaToken */; // strings case 34 /* CharacterCodes.doubleQuote */: pos++; value = scanString(); return token = 10 /* SyntaxKind.StringLiteral */; // comments case 47 /* CharacterCodes.slash */: const start = pos - 1; // Single-line comment if (text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) { pos += 2; while (pos < len) { if (isLineBreak(text.charCodeAt(pos))) { break; } pos++; } value = text.substring(start, pos); return token = 12 /* SyntaxKind.LineCommentTrivia */; } // Multi-line comment if (text.charCodeAt(pos + 1) === 42 /* CharacterCodes.asterisk */) { pos += 2; const safeLength = len - 1; // For lookahead. let commentClosed = false; while (pos < safeLength) { const ch = text.charCodeAt(pos); if (ch === 42 /* CharacterCodes.asterisk */ && text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) { pos += 2; commentClosed = true; break; } pos++; if (isLineBreak(ch)) { if (ch === 13 /* CharacterCodes.carriageReturn */ && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) { pos++; } lineNumber++; tokenLineStartOffset = pos; } } if (!commentClosed) { pos++; scanError = 1 /* ScanError.UnexpectedEndOfComment */; } value = text.substring(start, pos); return token = 13 /* SyntaxKind.BlockCommentTrivia */; } // just a single slash value += String.fromCharCode(code); pos++; return token = 16 /* SyntaxKind.Unknown */; // numbers case 45 /* CharacterCodes.minus */: value += String.fromCharCode(code); pos++; if (pos === len || !isDigit(text.charCodeAt(pos))) { return token = 16 /* SyntaxKind.Unknown */; } // found a minus, followed by a number so // we fall through to proceed with scanning // numbers case 48 /* CharacterCodes._0 */: case 49 /* CharacterCodes._1 */: case 50 /* CharacterCodes._2 */: case 51 /* CharacterCodes._3 */: case 52 /* CharacterCodes._4 */: case 53 /* CharacterCodes._5 */: case 54 /* CharacterCodes._6 */: case 55 /* CharacterCodes._7 */: case 56 /* CharacterCodes._8 */: case 57 /* CharacterCodes._9 */: value += scanNumber(); return token = 11 /* SyntaxKind.NumericLiteral */; // literals and unknown symbols default: // is a literal? Read the full word. while (pos < len && isUnknownContentCharacter(code)) { pos++; code = text.charCodeAt(pos); } if (tokenOffset !== pos) { value = text.substring(tokenOffset, pos); // keywords: true, false, null switch (value) { case 'true': return token = 8 /* SyntaxKind.TrueKeyword */; case 'false': return token = 9 /* SyntaxKind.FalseKeyword */; case 'null': return token = 7 /* SyntaxKind.NullKeyword */; } return token = 16 /* SyntaxKind.Unknown */; } // some value += String.fromCharCode(code); pos++; return token = 16 /* SyntaxKind.Unknown */; } } function isUnknownContentCharacter(code) { if (isWhiteSpace(code) || isLineBreak(code)) { return false; } switch (code) { case 125 /* CharacterCodes.closeBrace */: case 93 /* CharacterCodes.closeBracket */: case 123 /* CharacterCodes.openBrace */: case 91 /* CharacterCodes.openBracket */: case 34 /* CharacterCodes.doubleQuote */: case 58 /* CharacterCodes.colon */: case 44 /* CharacterCodes.comma */: case 47 /* CharacterCodes.slash */: return false; } return true; } function scanNextNonTrivia() { let result; do { result = scanNext(); } while (result >= 12 /* SyntaxKind.LineCommentTrivia */ && result <= 15 /* SyntaxKind.Trivia */); return result; } return { setPosition: setPosition, getPosition: () => pos, scan: ignoreTrivia ? scanNextNonTrivia : scanNext, getToken: () => token, getTokenValue: () => value, getTokenOffset: () => tokenOffset, getTokenLength: () => pos - tokenOffset, getTokenStartLine: () => lineStartOffset, getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset, getTokenError: () => scanError, }; } function isWhiteSpace(ch) { return ch === 32 /* CharacterCodes.space */ || ch === 9 /* CharacterCodes.tab */; } function isLineBreak(ch) { return ch === 10 /* CharacterCodes.lineFeed */ || ch === 13 /* CharacterCodes.carriageReturn */; } function isDigit(ch) { return ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */; } var CharacterCodes; (function (CharacterCodes) { CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed"; CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn"; CharacterCodes[CharacterCodes["space"] = 32] = "space"; CharacterCodes[CharacterCodes["_0"] = 48] = "_0"; CharacterCodes[CharacterCodes["_1"] = 49] = "_1"; CharacterCodes[CharacterCodes["_2"] = 50] = "_2"; CharacterCodes[CharacterCodes["_3"] = 51] = "_3"; CharacterCodes[CharacterCodes["_4"] = 52] = "_4"; CharacterCodes[CharacterCodes["_5"] = 53] = "_5"; CharacterCodes[CharacterCodes["_6"] = 54] = "_6"; CharacterCodes[CharacterCodes["_7"] = 55] = "_7"; CharacterCodes[CharacterCodes["_8"] = 56] = "_8"; CharacterCodes[CharacterCodes["_9"] = 57] = "_9"; CharacterCodes[CharacterCodes["a"] = 97] = "a"; CharacterCodes[CharacterCodes["b"] = 98] = "b"; CharacterCodes[CharacterCodes["c"] = 99] = "c"; CharacterCodes[CharacterCodes["d"] = 100] = "d"; CharacterCodes[CharacterCodes["e"] = 101] = "e"; CharacterCodes[CharacterCodes["f"] = 102] = "f"; CharacterCodes[CharacterCodes["g"] = 103] = "g"; CharacterCodes[CharacterCodes["h"] = 104] = "h"; CharacterCodes[CharacterCodes["i"] = 105] = "i"; CharacterCodes[CharacterCodes["j"] = 106] = "j"; CharacterCodes[CharacterCodes["k"] = 107] = "k"; CharacterCodes[CharacterCodes["l"] = 108] = "l"; CharacterCodes[CharacterCodes["m"] = 109] = "m"; CharacterCodes[CharacterCodes["n"] = 110] = "n"; CharacterCodes[CharacterCodes["o"] = 111] = "o"; CharacterCodes[CharacterCodes["p"] = 112] = "p"; CharacterCodes[CharacterCodes["q"] = 113] = "q"; CharacterCodes[CharacterCodes["r"] = 114] = "r"; CharacterCodes[CharacterCodes["s"] = 115] = "s"; CharacterCodes[CharacterCodes["t"] = 116] = "t"; CharacterCodes[CharacterCodes["u"] = 117] = "u"; CharacterCodes[CharacterCodes["v"] = 118] = "v"; CharacterCodes[CharacterCodes["w"] = 119] = "w"; CharacterCodes[CharacterCodes["x"] = 120] = "x"; CharacterCodes[CharacterCodes["y"] = 121] = "y"; CharacterCodes[CharacterCodes["z"] = 122] = "z"; CharacterCodes[CharacterCodes["A"] = 65] = "A"; CharacterCodes[CharacterCodes["B"] = 66] = "B"; CharacterCodes[CharacterCodes["C"] = 67] = "C"; CharacterCodes[CharacterCodes["D"] = 68] = "D"; CharacterCodes[CharacterCodes["E"] = 69] = "E"; CharacterCodes[CharacterCodes["F"] = 70] = "F"; CharacterCodes[CharacterCodes["G"] = 71] = "G"; CharacterCodes[CharacterCodes["H"] = 72] = "H"; CharacterCodes[CharacterCodes["I"] = 73] = "I"; CharacterCodes[CharacterCodes["J"] = 74] = "J"; CharacterCodes[CharacterCodes["K"] = 75] = "K"; CharacterCodes[CharacterCodes["L"] = 76] = "L"; CharacterCodes[CharacterCodes["M"] = 77] = "M"; CharacterCodes[CharacterCodes["N"] = 78] = "N"; CharacterCodes[CharacterCodes["O"] = 79] = "O"; CharacterCodes[CharacterCodes["P"] = 80] = "P"; CharacterCodes[CharacterCodes["Q"] = 81] = "Q"; CharacterCodes[CharacterCodes["R"] = 82] = "R"; CharacterCodes[CharacterCodes["S"] = 83] = "S"; CharacterCodes[CharacterCodes["T"] = 84] = "T"; CharacterCodes[CharacterCodes["U"] = 85] = "U"; CharacterCodes[CharacterCodes["V"] = 86] = "V"; CharacterCodes[CharacterCodes["W"] = 87] = "W"; CharacterCodes[CharacterCodes["X"] = 88] = "X"; CharacterCodes[CharacterCodes["Y"] = 89] = "Y"; CharacterCodes[CharacterCodes["Z"] = 90] = "Z"; CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk"; CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash"; CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace"; CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket"; CharacterCodes[CharacterCodes["colon"] = 58] = "colon"; CharacterCodes[CharacterCodes["comma"] = 44] = "comma"; CharacterCodes[CharacterCodes["dot"] = 46] = "dot"; CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote"; CharacterCodes[CharacterCodes["minus"] = 45] = "minus"; CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace"; CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket"; CharacterCodes[CharacterCodes["plus"] = 43] = "plus"; CharacterCodes[CharacterCodes["slash"] = 47] = "slash"; CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed"; CharacterCodes[CharacterCodes["tab"] = 9] = "tab"; })(CharacterCodes || (CharacterCodes = {})); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var ParseOptions; (function (ParseOptions) { ParseOptions.DEFAULT = { allowTrailingComma: false }; })(ParseOptions || (ParseOptions = {})); /** * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result. * Therefore always check the errors list to find out if the input was valid. */ function parse$1(text, errors = [], options = ParseOptions.DEFAULT) { let currentProperty = null; let currentParent = []; const previousParents = []; function onValue(value) { if (Array.isArray(currentParent)) { currentParent.push(value); } else if (currentProperty !== null) { currentParent[currentProperty] = value; } } const visitor = { onObjectBegin: () => { const object = {}; onValue(object); previousParents.push(currentParent); currentParent = object; currentProperty = null; }, onObjectProperty: (name) => { currentProperty = name; }, onObjectEnd: () => { currentParent = previousParents.pop(); }, onArrayBegin: () => { const array = []; onValue(array); previousParents.push(currentParent); currentParent = array; currentProperty = null; }, onArrayEnd: () => { currentParent = previousParents.pop(); }, onLiteralValue: onValue, onError: (error, offset, length) => { errors.push({ error, offset, length }); } }; visit(text, visitor, options); return currentParent[0]; } /** * Parses the given text and invokes the visitor functions for each object, array and literal reached. */ function visit(text, visitor, options = ParseOptions.DEFAULT) { const _scanner = createScanner(text, false); // Important: Only pass copies of this to visitor functions to prevent accidental modification, and // to not affect visitor functions which stored a reference to a previous JSONPath const _jsonPath = []; function toNoArgVisit(visitFunction) { return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true; } function toNoArgVisitWithPath(visitFunction) { return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true; } function toOneArgVisit(visitFunction) { return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true; } function toOneArgVisitWithPath(visitFunction) { return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true; } const onObjectBegin = toNoArgVisitWithPath(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisitWithPath(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError); const disallowComments = options && options.disallowComments; const allowTrailingComma = options && options.allowTrailingComma; function scanNext() { while (true) { const token = _scanner.scan(); switch (_scanner.getTokenError()) { case 4 /* ScanError.InvalidUnicode */: handleError(14 /* ParseErrorCode.InvalidUnicode */); break; case 5 /* ScanError.InvalidEscapeCharacter */: handleError(15 /* ParseErrorCode.InvalidEscapeCharacter */); break; case 3 /* ScanError.UnexpectedEndOfNumber */: handleError(13 /* ParseErrorCode.UnexpectedEndOfNumber */); break; case 1 /* ScanError.UnexpectedEndOfComment */: if (!disallowComments) { handleError(11 /* ParseErrorCode.UnexpectedEndOfComment */); } break; case 2 /* ScanError.UnexpectedEndOfString */: handleError(12 /* ParseErrorCode.UnexpectedEndOfS