Skip to content

Commit

Permalink
chore: enable glimmer parser on preview playground (#4915)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Aug 1, 2018
1 parent d83ca5a commit 1915cc3
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion scripts/build/build.js
Expand Up @@ -98,7 +98,7 @@ async function run(params) {
await execa("rm", ["-rf", ".cache"]);
}

const bundleCache = new Cache(".cache/", "v3");
const bundleCache = new Cache(".cache/", "v4");
await bundleCache.load();

console.log(chalk.inverse(" Building packages "));
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/config.js
Expand Up @@ -55,7 +55,7 @@ const parsers = [
},
{
input: "src/language-handlebars/parser-glimmer.js",
target: "node",
target: "universal",
commonjs: {
namedExports: {
"node_modules/handlebars/lib/index.js": ["parse"],
Expand Down
5 changes: 4 additions & 1 deletion src/cli/util.js
Expand Up @@ -629,6 +629,7 @@ function createOptionUsageType(option) {
return null;
case "choice":
return `<${option.choices
.filter(choice => choice.since !== null)
.filter(choice => !choice.deprecated)
.map(choice => choice.value)
.join("|")}>`;
Expand Down Expand Up @@ -676,7 +677,9 @@ function getOptionWithLevenSuggestion(context, options, optionName) {
}

function createChoiceUsages(choices, margin, indentation) {
const activeChoices = choices.filter(choice => !choice.deprecated);
const activeChoices = choices.filter(
choice => !choice.deprecated && choice.since !== null
);
const threshold =
activeChoices
.map(choice => choice.value.length)
Expand Down
7 changes: 6 additions & 1 deletion src/main/core-options.js
Expand Up @@ -116,7 +116,12 @@ const options = {
{ value: "graphql", since: "1.5.0", description: "GraphQL" },
{ value: "markdown", since: "1.8.0", description: "Markdown" },
{ value: "vue", since: "1.10.0", description: "Vue" },
{ value: "yaml", since: "1.14.0", description: "YAML" }
{ value: "yaml", since: "1.14.0", description: "YAML" },
{
value: "glimmer",
since: null,
description: "Handlebars"
}
]
},
plugins: {
Expand Down
7 changes: 1 addition & 6 deletions src/main/support.js
Expand Up @@ -78,12 +78,7 @@ function getSupportInfo(version, opts) {

const languages = plugins
.reduce((all, plugin) => all.concat(plugin.languages || []), [])
.filter(
language =>
language.since
? semver.gte(version, language.since)
: language.since !== null
)
.filter(filterSince)
.map(language => {
// Prevent breaking changes
if (language.name === "Markdown") {
Expand Down
1 change: 1 addition & 0 deletions standalone.js
Expand Up @@ -12,6 +12,7 @@ const internalPlugins = [
require("./src/language-js"),
require("./src/language-css"),
require("./src/language-graphql"),
require("./src/language-handlebars"),
require("./src/language-markdown"),
require("./src/language-vue"),
require("./src/language-yaml")
Expand Down
1 change: 1 addition & 0 deletions tests_config/require_standalone.js
Expand Up @@ -10,6 +10,7 @@ const sources = [
"parser-flow.js",
"parser-typescript.js",
"parser-postcss.js",
"parser-glimmer.js",
"parser-graphql.js",
"parser-markdown.js",
"parser-vue.js",
Expand Down
2 changes: 1 addition & 1 deletion tests_config/run_spec.js
Expand Up @@ -127,7 +127,7 @@ function read(filename) {
}

function skipStandalone(parser) {
return new Set(["parse5", "glimmer"]).has(parser);
return new Set(["parse5"]).has(parser);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions website/playground/codeSamples.js
Expand Up @@ -227,6 +227,15 @@ export default function(parser) {
" Billsmer @ 338-4338.",
""
].join("\n");
case "glimmer":
// modified from http://handlebarsjs.com/
return [
' <div class="entry" >',
" <h1>{{ title }}</h1>",
' <div class="body">',
" {{ body }}",
"</div> </div>"
].join("\n");
default:
return "";
}
Expand Down
5 changes: 5 additions & 0 deletions website/playground/markdown.js
Expand Up @@ -40,6 +40,11 @@ function getMarkdownSyntax(options) {
return "jsx";
case "typescript":
return "tsx";
case "json":
case "json-stringify":
return "jsonc";
case "glimmer":
return "hbs";
default:
return options.parser;
}
Expand Down
4 changes: 2 additions & 2 deletions website/static/service-worker.js
Expand Up @@ -7,15 +7,15 @@ importScripts("https://unpkg.com/sw-toolbox@3.6.0/sw-toolbox.js");

toolbox.precache([
// Scripts
"lib/index.js",
"lib/standalone.js",
"lib/parser-babylon.js",
"lib/parser-typescript.js",
"lib/parser-postcss.js",
"lib/parser-flow.js",
"lib/parser-json-stringify.js",
"lib/parser-glimmer.js",
"lib/parser-graphql.js",
"lib/parser-markdown.js",
"lib/parser-vue.js",
"lib/parser-yaml.js",
"playground.js",
"https://unpkg.com/sw-toolbox@3.6.0/sw-toolbox.js",
Expand Down
14 changes: 13 additions & 1 deletion website/static/worker.js
Expand Up @@ -76,6 +76,12 @@ var parsers = {
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;
}
};

Expand All @@ -94,7 +100,13 @@ function handleMessage(message) {
if (message.type === "meta") {
return {
type: "meta",
supportInfo: JSON.parse(JSON.stringify(prettier.getSupportInfo())),
supportInfo: JSON.parse(
JSON.stringify(
prettier.getSupportInfo(null, {
showUnreleased: /-pr\./.test(prettier.version)
})
)
),
version: prettier.version
};
}
Expand Down

0 comments on commit 1915cc3

Please sign in to comment.