prettier-plugin-marko
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -397,15 +397,2 @@ "use strict"; | ||
var currentConfig; | ||
function getCurrentCompiler() { | ||
try { | ||
return [ | ||
currentCompiler || (currentCompiler = rootRequire("@marko/compiler")), | ||
currentConfig || (currentConfig = rootRequire("@marko/compiler/config").default) | ||
]; | ||
} catch (cause) { | ||
throw new Error( | ||
"You must have @marko/compiler installed to use prettier-plugin-marko.", | ||
{ cause } | ||
); | ||
} | ||
} | ||
var languages = [ | ||
@@ -467,34 +454,7 @@ { | ||
async parse(text, opts) { | ||
ensureCompiler(); | ||
const { filepath = defaultFilePath } = opts; | ||
const [{ compile, types: t }, config] = getCurrentCompiler(); | ||
const translator = (() => { | ||
try { | ||
return rootRequire(config.translator); | ||
} catch (err) { | ||
throw new Error("Unable to find Marko translator.", { cause: err }); | ||
} | ||
})(); | ||
const { compile, types: t } = currentCompiler; | ||
const { ast } = await compile(`${text} | ||
`, filepath, { | ||
...config, | ||
translator, | ||
ast: true, | ||
code: false, | ||
optimize: false, | ||
output: "source", | ||
sourceMaps: false, | ||
writeVersionComment: false, | ||
babelConfig: { | ||
caller: { name: "@marko/prettier" }, | ||
babelrc: false, | ||
configFile: false, | ||
parserOpts: { | ||
allowUndeclaredExports: true, | ||
allowAwaitOutsideFunction: true, | ||
allowReturnOutsideFunction: true, | ||
allowImportExportEverywhere: true, | ||
plugins: ["exportDefaultFrom", "importAssertions"] | ||
} | ||
} | ||
}); | ||
`, filepath, currentConfig); | ||
opts.originalText = text; | ||
@@ -915,5 +875,6 @@ opts.markoLinePositions = [0]; | ||
embed(path, opts) { | ||
ensureCompiler(); | ||
const node = path.getNode(); | ||
const type = node == null ? void 0 : node.type; | ||
const [{ types: t }] = getCurrentCompiler(); | ||
const { types: t } = currentCompiler; | ||
switch (type) { | ||
@@ -1225,4 +1186,4 @@ case "File": | ||
getVisitorKeys(node) { | ||
const [compiler] = getCurrentCompiler(); | ||
return compiler.types.VISITOR_KEYS[node.type] || emptyArr; | ||
ensureCompiler(); | ||
return currentCompiler.types.VISITOR_KEYS[node.type] || emptyArr; | ||
} | ||
@@ -1233,3 +1194,3 @@ } | ||
currentCompiler = compiler; | ||
currentConfig = config; | ||
setConfig(config); | ||
} | ||
@@ -1358,2 +1319,48 @@ function printSpecialDeclaration(path, prefix, opts, print) { | ||
} | ||
function ensureCompiler() { | ||
if (!currentConfig) { | ||
let config; | ||
try { | ||
currentCompiler = rootRequire("@marko/compiler"); | ||
config = rootRequire("@marko/compiler/config").default; | ||
} catch (cause) { | ||
throw new Error( | ||
"You must have @marko/compiler installed to use prettier-plugin-marko.", | ||
{ cause } | ||
); | ||
} | ||
setConfig(config); | ||
} | ||
} | ||
function setConfig(config) { | ||
let { translator } = config; | ||
if (typeof translator === "string") { | ||
try { | ||
translator = rootRequire(translator); | ||
} catch { | ||
} | ||
} | ||
currentConfig = { | ||
...config, | ||
translator, | ||
ast: true, | ||
code: false, | ||
optimize: false, | ||
output: "source", | ||
sourceMaps: false, | ||
writeVersionComment: false, | ||
babelConfig: { | ||
caller: { name: "@marko/prettier" }, | ||
babelrc: false, | ||
configFile: false, | ||
parserOpts: { | ||
allowUndeclaredExports: true, | ||
allowAwaitOutsideFunction: true, | ||
allowReturnOutsideFunction: true, | ||
allowImportExportEverywhere: true, | ||
plugins: ["exportDefaultFrom", "importAssertions"] | ||
} | ||
} | ||
}; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -1360,0 +1367,0 @@ 0 && (module.exports = { |
{ | ||
"name": "prettier-plugin-marko", | ||
"description": "A prettier plugin for parsing and printing Marko files", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"author": "Dylan Piercey <dpiercey@ebay.com>", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/marko-js/prettier/issues", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2731
98977