Skip to content

Commit

Permalink
add curly braces when attribute shorthand is used but not allowed, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseskinner committed Aug 18, 2020
1 parent c7446d3 commit adb6c93
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,21 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D

if (isAttributeShorthand && options.svelteAllowShorthand) {
return concat([line, '{', node.name, '}']);
} else {
const def: Doc[] = [line, node.name];
if (node.value !== true) {
def.push('=');
const quotes = !hasLoneMustacheTag || options.svelteStrictMode;

quotes && def.push('"');
def.push(...path.map(childPath => childPath.call(print), 'value'));
quotes && def.push('"');
}
return concat(def);
}
} else {
const def: Doc[] = [line, node.name];
if (node.value !== true) {
def.push('=');
const quotes = !hasLoneMustacheTag || options.svelteStrictMode;
const curlies = quotes && isAttributeShorthand && !options.svelteAllowShorthand;

quotes && def.push('"');
curlies && def.push('{');
def.push(...path.map(childPath => childPath.call(print), 'value'));
curlies && def.push('}');
quotes && def.push('"');
}
return concat(def);
}
}
case 'MustacheTag':
return concat(['{', printJS(path, print, 'expression'), '}']);
Expand Down

0 comments on commit adb6c93

Please sign in to comment.