Files
test-repo/tests_config/require_standalone.js
T
Ika dcf44ffbdc feat: support YAML (#4563)
* feat: support YAML

* fix: do not indent sequence in mappingValue

* docs: add yaml to index.md

* fix: reduce `SyntaxError: Node#parse consumed no characters`

* chore: remove old-build and new-worker.js

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* fix: no space after `<<`

* fix: add yaml to standalone test

* test: add tests

* fix: next empty line in flow collection

* fix: tabs are not allowed
http://yaml.org/spec/1.2/spec.html#space/indentation/

* fix: update parser

* feat: rewrite the mappingItem logic
* feat: indent sequence in mapping
* feat(doc): add ifBreak#groupId and group#id

* chore: fix node 4

* chore: add tools_yaml.svg

* chore: remove resolved TODO

* refactor: remove unnecessary workaround

* chore(worker): importScriptOnce

* chore(build): rename with babelPlugins

* make it rollup compatible

* feat: support singleQuote

* refactor
2018-06-21 10:29:42 +08:00

50 lines
1.2 KiB
JavaScript

"use strict";
const fs = require("fs");
const path = require("path");
const vm = require("vm");
const sources = [
"standalone.js",
"parser-babylon.js",
"parser-flow.js",
"parser-typescript.js",
"parser-postcss.js",
"parser-graphql.js",
"parser-markdown.js",
"parser-vue.js",
"parser-yaml.js"
].map(filename =>
fs.readFileSync(path.join(process.env.PRETTIER_DIR, filename), "utf-8")
);
const sandbox = vm.createContext();
vm.runInContext(sources.join(";"), sandbox);
// TODO: maybe expose (and write tests) for `format`, `utils`, and
// `__debug` methods
module.exports = {
formatWithCursor(input, options) {
return vm.runInNewContext(
`prettier.formatWithCursor(
$$$input,
Object.assign({ plugins: prettierPlugins }, $$$options)
);`,
Object.assign({ $$$input: input, $$$options: options }, sandbox)
);
},
__debug: {
parse(input, options, massage) {
return vm.runInNewContext(
`prettier.__debug.parse(
$$$input,
Object.assign({ plugins: prettierPlugins }, $$$options),
${JSON.stringify(massage)}
);`,
Object.assign({ $$$input: input, $$$options: options }, sandbox)
);
}
}
};