Auto generate parsers for playground (#8771)
This commit is contained in:
1 parent
089de76d42
commit
f5c40bf977
3 files changed
+56
-147
No files matched your search
@@ -1,23 +1,18 @@
|
||||
/* eslint-env serviceworker */
|
||||
/* global toolbox */
|
||||
/* global toolbox parsersLocation */
|
||||
|
||||
"use strict";
|
||||
|
||||
importScripts("lib/parsers-location.js");
|
||||
importScripts("https://unpkg.com/sw-toolbox@3.6.0/sw-toolbox.js");
|
||||
|
||||
const parsers = Object.keys(parsersLocation).map((file) => `lib/${file}`);
|
||||
|
||||
toolbox.precache([
|
||||
// Scripts
|
||||
"lib/standalone.js",
|
||||
"lib/parser-angular.js",
|
||||
"lib/parser-babel.js",
|
||||
"lib/parser-flow.js",
|
||||
"lib/parser-glimmer.js",
|
||||
"lib/parser-graphql.js",
|
||||
"lib/parser-html.js",
|
||||
"lib/parser-markdown.js",
|
||||
"lib/parser-postcss.js",
|
||||
"lib/parser-typescript.js",
|
||||
"lib/parser-yaml.js",
|
||||
"lib/parsers-location.js",
|
||||
...parsers,
|
||||
"playground.js",
|
||||
"https://unpkg.com/sw-toolbox@3.6.0/sw-toolbox.js",
|
||||
|
||||
|
||||
+19
-135
@@ -1,6 +1,6 @@
|
||||
/* eslint-env worker */
|
||||
/* eslint no-var: off, strict: off */
|
||||
/* globals prettier prettierPlugins */
|
||||
/* globals prettier prettierPlugins parsersLocation */
|
||||
|
||||
var imported = Object.create(null);
|
||||
function importScriptOnce(url) {
|
||||
@@ -10,141 +10,25 @@ function importScriptOnce(url) {
|
||||
}
|
||||
}
|
||||
|
||||
// this is required to only load parsers when we need them
|
||||
var parsers = {
|
||||
// JS - Babel
|
||||
get babel() {
|
||||
importScriptOnce("lib/parser-babel.js");
|
||||
return prettierPlugins.babel.parsers.babel;
|
||||
},
|
||||
get "babel-flow"() {
|
||||
importScriptOnce("lib/parser-babel.js");
|
||||
return prettierPlugins.babel.parsers["babel-flow"];
|
||||
},
|
||||
get "babel-ts"() {
|
||||
importScriptOnce("lib/parser-babel.js");
|
||||
return prettierPlugins.babel.parsers["babel-ts"];
|
||||
},
|
||||
get json() {
|
||||
importScriptOnce("lib/parser-babel.js");
|
||||
return prettierPlugins.babel.parsers.json;
|
||||
},
|
||||
get json5() {
|
||||
importScriptOnce("lib/parser-babel.js");
|
||||
return prettierPlugins.babel.parsers.json5;
|
||||
},
|
||||
get "json-stringify"() {
|
||||
importScriptOnce("lib/parser-babel.js");
|
||||
return prettierPlugins.babel.parsers["json-stringify"];
|
||||
},
|
||||
get __js_expression() {
|
||||
importScriptOnce("lib/parser-babel.js");
|
||||
return prettierPlugins.babel.parsers.__js_expression;
|
||||
},
|
||||
get __vue_expression() {
|
||||
importScriptOnce("lib/parser-babel.js");
|
||||
return prettierPlugins.babel.parsers.__vue_expression;
|
||||
},
|
||||
get __vue_event_binding() {
|
||||
importScriptOnce("lib/parser-babel.js");
|
||||
return prettierPlugins.babel.parsers.__vue_event_binding;
|
||||
},
|
||||
// JS - Flow
|
||||
get flow() {
|
||||
importScriptOnce("lib/parser-flow.js");
|
||||
return prettierPlugins.flow.parsers.flow;
|
||||
},
|
||||
// JS - TypeScript
|
||||
get typescript() {
|
||||
importScriptOnce("lib/parser-typescript.js");
|
||||
return prettierPlugins.typescript.parsers.typescript;
|
||||
},
|
||||
// JS - Angular Action
|
||||
get __ng_action() {
|
||||
importScriptOnce("lib/parser-angular.js");
|
||||
return prettierPlugins.angular.parsers.__ng_action;
|
||||
},
|
||||
// JS - Angular Binding
|
||||
get __ng_binding() {
|
||||
importScriptOnce("lib/parser-angular.js");
|
||||
return prettierPlugins.angular.parsers.__ng_binding;
|
||||
},
|
||||
// JS - Angular Interpolation
|
||||
get __ng_interpolation() {
|
||||
importScriptOnce("lib/parser-angular.js");
|
||||
return prettierPlugins.angular.parsers.__ng_interpolation;
|
||||
},
|
||||
// JS - Angular Directive
|
||||
get __ng_directive() {
|
||||
importScriptOnce("lib/parser-angular.js");
|
||||
return prettierPlugins.angular.parsers.__ng_directive;
|
||||
},
|
||||
|
||||
// CSS
|
||||
get css() {
|
||||
importScriptOnce("lib/parser-postcss.js");
|
||||
return prettierPlugins.postcss.parsers.css;
|
||||
},
|
||||
get less() {
|
||||
importScriptOnce("lib/parser-postcss.js");
|
||||
return prettierPlugins.postcss.parsers.css;
|
||||
},
|
||||
get scss() {
|
||||
importScriptOnce("lib/parser-postcss.js");
|
||||
return prettierPlugins.postcss.parsers.css;
|
||||
},
|
||||
|
||||
// GraphQL
|
||||
get graphql() {
|
||||
importScriptOnce("lib/parser-graphql.js");
|
||||
return prettierPlugins.graphql.parsers.graphql;
|
||||
},
|
||||
|
||||
// Markdown
|
||||
get markdown() {
|
||||
importScriptOnce("lib/parser-markdown.js");
|
||||
return prettierPlugins.markdown.parsers.remark;
|
||||
},
|
||||
get mdx() {
|
||||
importScriptOnce("lib/parser-markdown.js");
|
||||
return prettierPlugins.markdown.parsers.mdx;
|
||||
},
|
||||
|
||||
// YAML
|
||||
get yaml() {
|
||||
importScriptOnce("lib/parser-yaml.js");
|
||||
return prettierPlugins.yaml.parsers.yaml;
|
||||
},
|
||||
|
||||
// Handlebars
|
||||
get glimmer() {
|
||||
importScriptOnce("lib/parser-glimmer.js");
|
||||
return prettierPlugins.glimmer.parsers.glimmer;
|
||||
},
|
||||
|
||||
// HTML
|
||||
get html() {
|
||||
importScriptOnce("lib/parser-html.js");
|
||||
return prettierPlugins.html.parsers.html;
|
||||
},
|
||||
// Vue
|
||||
get vue() {
|
||||
importScriptOnce("lib/parser-html.js");
|
||||
return prettierPlugins.html.parsers.vue;
|
||||
},
|
||||
// Angular
|
||||
get angular() {
|
||||
importScriptOnce("lib/parser-html.js");
|
||||
return prettierPlugins.html.parsers.angular;
|
||||
},
|
||||
// Lightning Web Components
|
||||
get lwc() {
|
||||
importScriptOnce("lib/parser-html.js");
|
||||
return prettierPlugins.html.parsers.lwc;
|
||||
},
|
||||
};
|
||||
|
||||
importScripts("lib/parsers-location.js");
|
||||
importScripts("lib/standalone.js");
|
||||
|
||||
// this is required to only load parsers when we need them
|
||||
const parsers = Object.create(null);
|
||||
|
||||
for (const file in parsersLocation) {
|
||||
const { parsers: moduleParsers, property } = parsersLocation[file];
|
||||
const url = `lib/${file}`;
|
||||
for (const parserName of moduleParsers) {
|
||||
Object.defineProperty(parsers, parserName, {
|
||||
get() {
|
||||
importScriptOnce(url);
|
||||
return prettierPlugins[property].parsers[parserName];
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
var PRETTIER_DEBUG = true;
|
||||
|
||||
|
||||
Reference in new issue
Block a user