svelte-ast-print
Version:
Serialize Svelte AST nodes into stringified syntax. A.k.a parse in reverse.
27 lines • 881 B
JavaScript
import * as char from "../char.js";
import { print_js } from "../js.js";
import { State } from "../shared.js";
import { CurlyBrackets } from "../wrapper.js";
/**
* @internal
* @__NO_SIDE_EFFECTS__
*/
export function is_attr_exp_shorthand(n, exp) {
return exp.type === "Identifier" && exp.name === n.name;
}
/**
* @internal
* Abstraction for printing shared schema in directives.
* @__NO_SIDE_EFFECTS__
*/
export function print_directive(name, n, opts = {}) {
const st = State.get(n, opts);
st.add(name, char.COLON, n.name);
if ("modifiers" in n && n.modifiers.length > 0)
st.add(char.PIPE, n.modifiers.join(char.PIPE));
if (n.expression && !is_attr_exp_shorthand(n, n.expression)) {
st.add(char.ASSIGN, new CurlyBrackets("inline", print_js(n.expression, st.opts)));
}
return st.result;
}
//# sourceMappingURL=attribute-like.js.map