add trailing commas to prettier config, only run on .ts files

pull/618/head
Rich Harris 7 years ago
parent 485d7b4ef1
commit b0a1616e31

@ -24,7 +24,7 @@
"dev:shared": "rollup -c rollup/rollup.config.shared.js -w", "dev:shared": "rollup -c rollup/rollup.config.shared.js -w",
"pretest": "npm run build", "pretest": "npm run build",
"prepublish": "npm run build && npm run lint", "prepublish": "npm run build && npm run lint",
"prettier": "prettier --use-tabs --single-quote --write \"src/**/*.ts\" \"src/**/*.js\"" "prettier": "prettier --use-tabs --single-quote --trailing-comma es5 --write \"src/**/*.ts\""
}, },
"repository": { "repository": {
"type": "git", "type": "git",

@ -84,7 +84,7 @@ export default class Generator {
enter: (node: Node) => { enter: (node: Node) => {
this.code.addSourcemapLocation(node.start); this.code.addSourcemapLocation(node.start);
this.code.addSourcemapLocation(node.end); this.code.addSourcemapLocation(node.end);
} },
}); });
} }
@ -127,7 +127,7 @@ export default class Generator {
if (lexicalDepth === 0 && context) if (lexicalDepth === 0 && context)
code.overwrite(node.start, node.end, context, { code.overwrite(node.start, node.end, context, {
storeName: true, storeName: true,
contentOnly: false contentOnly: false,
}); });
} else if (isReference(node, parent)) { } else if (isReference(node, parent)) {
const { name } = flattenReference(node); const { name } = flattenReference(node);
@ -182,13 +182,13 @@ export default class Generator {
leave(node: Node) { leave(node: Node) {
if (/^Function/.test(node.type)) lexicalDepth -= 1; if (/^Function/.test(node.type)) lexicalDepth -= 1;
if (node._scope) scope = scope.parent; if (node._scope) scope = scope.parent;
} },
}); });
return { return {
dependencies: expression._dependencies, // TODO probably a better way to do this dependencies: expression._dependencies, // TODO probably a better way to do this
contexts: usedContexts, contexts: usedContexts,
snippet: `[✂${expression.start}-${expression.end}✂]` snippet: `[✂${expression.start}-${expression.end}✂]`,
}; };
} }
@ -227,7 +227,7 @@ export default class Generator {
leave(node: Node) { leave(node: Node) {
if (node._scope) scope = scope.parent; if (node._scope) scope = scope.parent;
} },
}); });
dependencies.forEach(name => { dependencies.forEach(name => {
@ -294,7 +294,7 @@ export default class Generator {
function addString(str: string) { function addString(str: string) {
compiled.addSource({ compiled.addSource({
content: new MagicString(str) content: new MagicString(str),
}); });
} }
@ -308,7 +308,7 @@ export default class Generator {
if (!parts.length) { if (!parts.length) {
compiled.addSource({ compiled.addSource({
filename, filename,
content: new MagicString(this.source).remove(0, this.source.length) content: new MagicString(this.source).remove(0, this.source.length),
}); });
} }
@ -322,7 +322,7 @@ export default class Generator {
compiled.addSource({ compiled.addSource({
filename, filename,
content: snippet content: snippet,
}); });
}); });
@ -333,9 +333,9 @@ export default class Generator {
code: compiled.toString(), code: compiled.toString(),
map: compiled.generateMap({ map: compiled.generateMap({
includeContent: true, includeContent: true,
file: options.outputFilename file: options.outputFilename,
}), }),
css: this.css css: this.css,
}; };
} }
@ -493,7 +493,7 @@ export default class Generator {
const { key } = templateProperties.onrender; const { key } = templateProperties.onrender;
this.code.overwrite(key.start, key.end, 'oncreate', { this.code.overwrite(key.start, key.end, 'oncreate', {
storeName: true, storeName: true,
contentOnly: false contentOnly: false,
}); });
templateProperties.oncreate = templateProperties.onrender; templateProperties.oncreate = templateProperties.onrender;
} }
@ -502,7 +502,7 @@ export default class Generator {
const { key } = templateProperties.onteardown; const { key } = templateProperties.onteardown;
this.code.overwrite(key.start, key.end, 'ondestroy', { this.code.overwrite(key.start, key.end, 'ondestroy', {
storeName: true, storeName: true,
contentOnly: false contentOnly: false,
}); });
templateProperties.ondestroy = templateProperties.onteardown; templateProperties.ondestroy = templateProperties.onteardown;
} }
@ -597,7 +597,7 @@ export default class Generator {
computations, computations,
hasJs, hasJs,
namespace, namespace,
templateProperties templateProperties,
}; };
} }
} }

@ -93,7 +93,7 @@ export default class Block {
outro: new CodeBuilder(), outro: new CodeBuilder(),
unmount: new CodeBuilder(), unmount: new CodeBuilder(),
detachRaw: new CodeBuilder(), detachRaw: new CodeBuilder(),
destroy: new CodeBuilder() destroy: new CodeBuilder(),
}; };
this.hasIntroMethod = false; // a block could have an intro method but not intro transitions, e.g. if a sibling block has intros this.hasIntroMethod = false; // a block could have an intro method but not intro transitions, e.g. if a sibling block has intros

@ -63,7 +63,7 @@ export default function dom(
computations, computations,
hasJs, hasJs,
templateProperties, templateProperties,
namespace namespace,
} = generator.parseJs(); } = generator.parseJs();
const { block, state } = preprocess(generator, namespace, parsed.html); const { block, state } = preprocess(generator, namespace, parsed.html);
@ -74,7 +74,7 @@ export default function dom(
const builders = { const builders = {
main: new CodeBuilder(), main: new CodeBuilder(),
_set: new CodeBuilder() _set: new CodeBuilder(),
}; };
if (computations.length) { if (computations.length) {
@ -319,7 +319,7 @@ export default function dom(
leave(node) { leave(node) {
if (node._scope) scope = scope.parent; if (node._scope) scope = scope.parent;
} },
}); });
if (key === 'transitionManager') { if (key === 'transitionManager') {
@ -343,6 +343,6 @@ export default function dom(
return generator.generate(builders.main.toString(), options, { return generator.generate(builders.main.toString(), options, {
name, name,
format format,
}); });
} }

@ -26,7 +26,7 @@ const elementsWithoutText = new Set([
'optgroup', 'optgroup',
'select', 'select',
'ul', 'ul',
'video' 'video',
]); ]);
const preprocessors = { const preprocessors = {
@ -40,7 +40,7 @@ const preprocessors = {
block.addDependencies(dependencies); block.addDependencies(dependencies);
node._state = getChildState(state, { node._state = getChildState(state, {
name: block.getUniqueName('text') name: block.getUniqueName('text'),
}); });
}, },
@ -87,7 +87,7 @@ const preprocessors = {
block.addDependencies(dependencies); block.addDependencies(dependencies);
node._block = block.child({ node._block = block.child({
name: generator.getUniqueName(`create_if_block`) name: generator.getUniqueName(`create_if_block`),
}); });
node._state = getChildState(state); node._state = getChildState(state);
@ -107,7 +107,7 @@ const preprocessors = {
attachBlocks(node.else.children[0]); attachBlocks(node.else.children[0]);
} else if (node.else) { } else if (node.else) {
node.else._block = block.child({ node.else._block = block.child({
name: generator.getUniqueName(`create_if_block`) name: generator.getUniqueName(`create_if_block`),
}); });
node.else._state = getChildState(state); node.else._state = getChildState(state);
@ -181,11 +181,11 @@ const preprocessors = {
indexNames, indexNames,
listNames, listNames,
params: block.params.concat(listName, context, indexName) params: block.params.concat(listName, context, indexName),
}); });
node._state = getChildState(state, { node._state = getChildState(state, {
inEachBlock: true inEachBlock: true,
}); });
generator.blocks.push(node._block); generator.blocks.push(node._block);
@ -195,7 +195,7 @@ const preprocessors = {
if (node.else) { if (node.else) {
node.else._block = block.child({ node.else._block = block.child({
name: generator.getUniqueName(`${node._block.name}_else`) name: generator.getUniqueName(`${node._block.name}_else`),
}); });
node.else._state = getChildState(state); node.else._state = getChildState(state);
@ -235,7 +235,7 @@ const preprocessors = {
namespace: node.name === 'svg' namespace: node.name === 'svg'
? 'http://www.w3.org/2000/svg' ? 'http://www.w3.org/2000/svg'
: state.namespace, : state.namespace,
allUsedContexts: [] allUsedContexts: [],
}); });
} }
@ -267,7 +267,7 @@ const preprocessors = {
); );
node._block = block.child({ node._block = block.child({
name: generator.getUniqueName(`create_${name}_yield_fragment`) name: generator.getUniqueName(`create_${name}_yield_fragment`),
}); });
generator.blocks.push(node._block); generator.blocks.push(node._block);
@ -278,7 +278,7 @@ const preprocessors = {
preprocessChildren(generator, block, node._state, node); preprocessChildren(generator, block, node._state, node);
} }
} }
} },
}; };
function preprocessChildren( function preprocessChildren(
@ -359,13 +359,13 @@ export default function preprocess(
indexNames: new Map(), indexNames: new Map(),
listNames: new Map(), listNames: new Map(),
dependencies: new Set() dependencies: new Set(),
}); });
const state: State = { const state: State = {
namespace, namespace,
parentNode: null, parentNode: null,
isTopLevel: true isTopLevel: true,
}; };
generator.blocks.push(block); generator.blocks.push(block);

@ -15,12 +15,12 @@ export default function visitAttribute(
// attributes without values, e.g. <textarea readonly> // attributes without values, e.g. <textarea readonly>
local.staticAttributes.push({ local.staticAttributes.push({
name: attribute.name, name: attribute.name,
value: true value: true,
}); });
} else if (attribute.value.length === 0) { } else if (attribute.value.length === 0) {
local.staticAttributes.push({ local.staticAttributes.push({
name: attribute.name, name: attribute.name,
value: `''` value: `''`,
}); });
} else if (attribute.value.length === 1) { } else if (attribute.value.length === 1) {
const value = attribute.value[0]; const value = attribute.value[0];
@ -32,7 +32,7 @@ export default function visitAttribute(
: value.data; : value.data;
local.staticAttributes.push({ local.staticAttributes.push({
name: attribute.name, name: attribute.name,
value: result value: result,
}); });
} else { } else {
// simple dynamic attributes // simple dynamic attributes
@ -42,7 +42,7 @@ export default function visitAttribute(
local.dynamicAttributes.push({ local.dynamicAttributes.push({
name: attribute.name, name: attribute.name,
value: snippet, value: snippet,
dependencies dependencies,
}); });
} }
} else { } else {
@ -72,7 +72,7 @@ export default function visitAttribute(
local.dynamicAttributes.push({ local.dynamicAttributes.push({
name: attribute.name, name: attribute.name,
value, value,
dependencies: allDependencies dependencies: allDependencies,
}); });
} }
} }

@ -50,7 +50,7 @@ export default function visitBinding(
name: attribute.name, name: attribute.name,
value: snippet, value: snippet,
obj, obj,
prop prop,
}); });
const setter = getSetter({ const setter = getSetter({
@ -60,7 +60,7 @@ export default function visitBinding(
context: '_context', context: '_context',
attribute, attribute,
dependencies, dependencies,
value: 'value' value: 'value',
}); });
generator.hasComplexBindings = true; generator.hasComplexBindings = true;

@ -26,14 +26,14 @@ const order = {
Attribute: 1, Attribute: 1,
EventHandler: 2, EventHandler: 2,
Binding: 3, Binding: 3,
Ref: 4 Ref: 4,
}; };
const visitors = { const visitors = {
Attribute: visitAttribute, Attribute: visitAttribute,
EventHandler: visitEventHandler, EventHandler: visitEventHandler,
Binding: visitBinding, Binding: visitBinding,
Ref: visitRef Ref: visitRef,
}; };
export default function visitComponent( export default function visitComponent(
@ -60,7 +60,7 @@ export default function visitComponent(
bindings: [], bindings: [],
create: new CodeBuilder(), create: new CodeBuilder(),
update: new CodeBuilder() update: new CodeBuilder(),
}; };
const isTopLevel = !state.parentNode; const isTopLevel = !state.parentNode;
@ -114,7 +114,7 @@ export default function visitComponent(
const componentInitProperties = [ const componentInitProperties = [
`target: ${!isTopLevel ? state.parentNode : 'null'}`, `target: ${!isTopLevel ? state.parentNode : 'null'}`,
`_root: ${block.component}._root` `_root: ${block.component}._root`,
]; ];
// Component has children, put them in a separate {{yield}} block // Component has children, put them in a separate {{yield}} block

@ -30,7 +30,7 @@ export default function visitEachBlock(
i, i,
params, params,
anchor, anchor,
mountOrIntro mountOrIntro,
}; };
const { snippet } = block.contextualise(node.expression); const { snippet } = block.contextualise(node.expression);
@ -144,7 +144,7 @@ function keyed(
i, i,
params, params,
anchor, anchor,
mountOrIntro mountOrIntro,
} }
) { ) {
const key = block.getUniqueName('key'); const key = block.getUniqueName('key');
@ -350,7 +350,7 @@ function unkeyed(
i, i,
params, params,
anchor, anchor,
mountOrIntro mountOrIntro,
} }
) { ) {
block.builders.create.addBlock(deindent` block.builders.create.addBlock(deindent`

@ -67,7 +67,7 @@ export default function visitBinding(
context: '_svelte', context: '_svelte',
attribute, attribute,
dependencies, dependencies,
value value,
}); });
let updateElement = `${state.parentNode}.${attribute.name} = ${snippet};`; let updateElement = `${state.parentNode}.${attribute.name} = ${snippet};`;
const lock = block.alias(`${state.parentNode}_updating`); const lock = block.alias(`${state.parentNode}_updating`);

@ -13,21 +13,21 @@ import { Node } from '../../../../interfaces';
import { State } from '../../interfaces'; import { State } from '../../interfaces';
const meta = { const meta = {
':Window': visitWindow ':Window': visitWindow,
}; };
const order = { const order = {
Attribute: 1, Attribute: 1,
Binding: 2, Binding: 2,
EventHandler: 3, EventHandler: 3,
Ref: 4 Ref: 4,
}; };
const visitors = { const visitors = {
Attribute: visitAttribute, Attribute: visitAttribute,
EventHandler: visitEventHandler, EventHandler: visitEventHandler,
Binding: visitBinding, Binding: visitBinding,
Ref: visitRef Ref: visitRef,
}; };
export default function visitElement( export default function visitElement(
@ -136,7 +136,7 @@ export default function visitElement(
node.attributes.push({ node.attributes.push({
type: 'Attribute', type: 'Attribute',
name: 'value', name: 'value',
value: node.children value: node.children,
}); });
node.children = []; node.children = [];

@ -85,7 +85,7 @@ export default function visitEventHandler(
if (shouldHoist) { if (shouldHoist) {
generator.blocks.push( generator.blocks.push(
<Block>{ <Block>{
render: () => handler render: () => handler,
} }
); );
} else { } else {

@ -19,8 +19,8 @@ const lookup = {
'tfoot', 'tfoot',
'th', 'th',
'thead', 'thead',
'tr' 'tr',
] ],
}, },
allowfullscreen: { propertyName: 'allowFullscreen', appliesTo: ['iframe'] }, allowfullscreen: { propertyName: 'allowFullscreen', appliesTo: ['iframe'] },
alt: { appliesTo: ['applet', 'area', 'img', 'input'] }, alt: { appliesTo: ['applet', 'area', 'img', 'input'] },
@ -41,8 +41,8 @@ const lookup = {
'tfoot', 'tfoot',
'td', 'td',
'th', 'th',
'tr' 'tr',
] ],
}, },
border: { appliesTo: ['img', 'object', 'table'] }, border: { appliesTo: ['img', 'object', 'table'] },
buffered: { appliesTo: ['audio', 'video'] }, buffered: { appliesTo: ['audio', 'video'] },
@ -77,8 +77,8 @@ const lookup = {
'optgroup', 'optgroup',
'option', 'option',
'select', 'select',
'textarea' 'textarea',
] ],
}, },
download: { appliesTo: ['a', 'area'] }, download: { appliesTo: ['a', 'area'] },
draggable: {}, draggable: {},
@ -97,13 +97,13 @@ const lookup = {
'output', 'output',
'progress', 'progress',
'select', 'select',
'textarea' 'textarea',
] ],
}, },
formaction: { appliesTo: ['input', 'button'] }, formaction: { appliesTo: ['input', 'button'] },
headers: { appliesTo: ['td', 'th'] }, headers: { appliesTo: ['td', 'th'] },
height: { height: {
appliesTo: ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video'] appliesTo: ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video'],
}, },
hidden: {}, hidden: {},
high: { appliesTo: ['meter'] }, high: { appliesTo: ['meter'] },
@ -143,8 +143,8 @@ const lookup = {
'textarea', 'textarea',
'map', 'map',
'meta', 'meta',
'param' 'param',
] ],
}, },
novalidate: { propertyName: 'noValidate', appliesTo: ['form'] }, novalidate: { propertyName: 'noValidate', appliesTo: ['form'] },
open: { appliesTo: ['details'] }, open: { appliesTo: ['details'] },
@ -181,8 +181,8 @@ const lookup = {
'script', 'script',
'source', 'source',
'track', 'track',
'video' 'video',
] ],
}, },
srcdoc: { appliesTo: ['iframe'] }, srcdoc: { appliesTo: ['iframe'] },
srclang: { appliesTo: ['track'] }, srclang: { appliesTo: ['track'] },
@ -204,8 +204,8 @@ const lookup = {
'script', 'script',
'source', 'source',
'style', 'style',
'menu' 'menu',
] ],
}, },
usemap: { propertyName: 'useMap', appliesTo: ['img', 'input', 'object'] }, usemap: { propertyName: 'useMap', appliesTo: ['img', 'input', 'object'] },
value: { value: {
@ -218,13 +218,13 @@ const lookup = {
'progress', 'progress',
'param', 'param',
'select', 'select',
'textarea' 'textarea',
] ],
}, },
width: { width: {
appliesTo: ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video'] appliesTo: ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video'],
}, },
wrap: { appliesTo: ['textarea'] } wrap: { appliesTo: ['textarea'] },
}; };
Object.keys(lookup).forEach(name => { Object.keys(lookup).forEach(name => {

@ -11,7 +11,7 @@ const associatedEvents = {
outerHeight: 'resize', outerHeight: 'resize',
scrollX: 'scroll', scrollX: 'scroll',
scrollY: 'scroll' scrollY: 'scroll',
}; };
const readonly = new Set([ const readonly = new Set([
@ -19,7 +19,7 @@ const readonly = new Set([
'innerHeight', 'innerHeight',
'outerWidth', 'outerWidth',
'outerHeight', 'outerHeight',
'online' 'online',
]); ]);
export default function visitWindow( export default function visitWindow(

@ -27,8 +27,8 @@ function getBranches(
block: node._block.name, block: node._block.name,
hasUpdateMethod: node._block.hasUpdateMethod, hasUpdateMethod: node._block.hasUpdateMethod,
hasIntroMethod: node._block.hasIntroMethod, hasIntroMethod: node._block.hasIntroMethod,
hasOutroMethod: node._block.hasOutroMethod hasOutroMethod: node._block.hasOutroMethod,
} },
]; ];
visitChildren(generator, block, state, node); visitChildren(generator, block, state, node);
@ -43,7 +43,7 @@ function getBranches(
block: node.else ? node.else._block.name : null, block: node.else ? node.else._block.name : null,
hasUpdateMethod: node.else ? node.else._block.hasUpdateMethod : false, hasUpdateMethod: node.else ? node.else._block.hasUpdateMethod : false,
hasIntroMethod: node.else ? node.else._block.hasIntroMethod : false, hasIntroMethod: node.else ? node.else._block.hasIntroMethod : false,
hasOutroMethod: node.else ? node.else._block.hasOutroMethod : false hasOutroMethod: node.else ? node.else._block.hasOutroMethod : false,
}); });
if (node.else) { if (node.else) {

@ -13,5 +13,5 @@ export default {
MustacheTag, MustacheTag,
RawMustacheTag, RawMustacheTag,
Text, Text,
YieldTag YieldTag,
}; };

@ -7,7 +7,7 @@ export default function getSetter({
context, context,
attribute, attribute,
dependencies, dependencies,
value value,
}) { }) {
const tail = attribute.value.type === 'MemberExpression' const tail = attribute.value.type === 'MemberExpression'
? getTailSnippet(attribute.value) ? getTailSnippet(attribute.value)

@ -43,7 +43,7 @@ export default function ssr(
generator, generator,
contexts: new Map(), contexts: new Map(),
indexes: new Map(), indexes: new Map(),
conditions: [] conditions: [],
}); });
parsed.html.children.forEach((node: Node) => { parsed.html.children.forEach((node: Node) => {

@ -29,7 +29,7 @@ export default function visitEachBlock(
const childBlock = block.child({ const childBlock = block.child({
contexts, contexts,
indexes, indexes,
contextDependencies contextDependencies,
}); });
node.children.forEach((child: Node) => { node.children.forEach((child: Node) => {

@ -7,7 +7,7 @@ import Block from '../Block';
import { Node } from '../../../interfaces'; import { Node } from '../../../interfaces';
const meta = { const meta = {
':Window': visitWindow ':Window': visitWindow,
}; };
function stringifyAttributeValue(block: Block, chunks: Node[]) { function stringifyAttributeValue(block: Block, chunks: Node[]) {

@ -13,7 +13,7 @@ export default function visitIfBlock(
generator.append('${ ' + snippet + ' ? `'); generator.append('${ ' + snippet + ' ? `');
const childBlock = block.child({ const childBlock = block.child({
conditions: block.conditions.concat(snippet) conditions: block.conditions.concat(snippet),
}); });
node.children.forEach((child: Node) => { node.children.forEach((child: Node) => {

@ -15,5 +15,5 @@ export default {
MustacheTag, MustacheTag,
RawMustacheTag, RawMustacheTag,
Text, Text,
YieldTag YieldTag,
}; };

@ -23,7 +23,7 @@ export default function getGlobals(imports: Declaration[], options: Options) {
} else { } else {
const warning = { const warning = {
message: `No name was supplied for imported module '${x.source message: `No name was supplied for imported module '${x.source
.value}'. Guessing '${x.name}', but you should use options.globals` .value}'. Guessing '${x.name}', but you should use options.globals`,
}; };
if (onwarn) { if (onwarn) {

@ -26,7 +26,7 @@ function normalizeOptions(options: CompileOptions): CompileOptions {
onerror: (error: Error) => { onerror: (error: Error) => {
throw error; throw error;
} },
}, },
options options
); );

@ -51,7 +51,7 @@ export class Parser {
start: null, start: null,
end: null, end: null,
type: 'Fragment', type: 'Fragment',
children: [] children: [],
}; };
this.css = null; this.css = null;
@ -197,6 +197,6 @@ export default function parse(
hash: hash(parser.template), hash: hash(parser.template),
html: parser.html, html: parser.html,
css: parser.css, css: parser.css,
js: parser.js js: parser.js,
}; };
} }

@ -60,7 +60,7 @@ export function readEventHandlerDirective(
end: parser.index, end: parser.index,
type: 'EventHandler', type: 'EventHandler',
name, name,
expression expression,
}; };
} }
@ -114,7 +114,7 @@ export function readBindingDirective(
type: 'Identifier', type: 'Identifier',
start: start + 5, start: start + 5,
end: parser.index, end: parser.index,
name name,
}; };
} }
@ -123,7 +123,7 @@ export function readBindingDirective(
end: parser.index, end: parser.index,
type: 'Binding', type: 'Binding',
name, name,
value value,
}; };
} }
@ -154,6 +154,6 @@ export function readTransitionDirective(
name, name,
intro: type === 'in' || type === 'transition', intro: type === 'in' || type === 'transition',
outro: type === 'out' || type === 'transition', outro: type === 'out' || type === 'transition',
expression expression,
}; };
} }

@ -16,7 +16,7 @@ export default function readExpression(parser: Parser) {
start, start,
end, end,
value: literals.get(name), value: literals.get(name),
raw: name raw: name,
}; };
} }
@ -24,7 +24,7 @@ export default function readExpression(parser: Parser) {
type: 'Identifier', type: 'Identifier',
start, start,
end: start + name.length, end: start + name.length,
name name,
}; };
} }
@ -32,7 +32,7 @@ export default function readExpression(parser: Parser) {
try { try {
const node = parseExpressionAt(parser.template, parser.index, { const node = parseExpressionAt(parser.template, parser.index, {
preserveParens: true preserveParens: true,
}); });
parser.index = node.end; parser.index = node.end;

@ -19,7 +19,7 @@ export default function readScript(parser: Parser, start: number, attributes) {
try { try {
ast = parse(source, { ast = parse(source, {
ecmaVersion: 8, ecmaVersion: 8,
sourceType: 'module' sourceType: 'module',
}); });
} catch (err) { } catch (err) {
parser.acornError(err); parser.acornError(err);
@ -32,6 +32,6 @@ export default function readScript(parser: Parser, start: number, attributes) {
start, start,
end: parser.index, end: parser.index,
attributes, attributes,
content: ast content: ast,
}; };
} }

@ -12,7 +12,7 @@ export default function readStyle(parser: Parser, start: number, attributes) {
try { try {
ast = parse(styles, { ast = parse(styles, {
positions: true, positions: true,
offset: contentStart offset: contentStart,
}); });
} catch (err) { } catch (err) {
if (err.name === 'CssSyntaxError') { if (err.name === 'CssSyntaxError') {
@ -42,7 +42,7 @@ export default function readStyle(parser: Parser, start: number, attributes) {
content: { content: {
start: contentStart, start: contentStart,
end: contentEnd, end: contentEnd,
styles styles,
} },
}; };
} }

@ -105,9 +105,9 @@ export default function mustache(parser: Parser) {
type: 'IfBlock', type: 'IfBlock',
elseif: true, elseif: true,
expression, expression,
children: [] children: [],
} },
] ],
}; };
parser.stack.push(block.else.children[0]); parser.stack.push(block.else.children[0]);
@ -126,7 +126,7 @@ export default function mustache(parser: Parser) {
start: parser.index, start: parser.index,
end: null, end: null,
type: 'ElseBlock', type: 'ElseBlock',
children: [] children: [],
}; };
parser.stack.push(block.else); parser.stack.push(block.else);
@ -151,7 +151,7 @@ export default function mustache(parser: Parser) {
end: null, end: null,
type, type,
expression, expression,
children: [] children: [],
}; };
parser.allowWhitespace(); parser.allowWhitespace();
@ -192,7 +192,7 @@ export default function mustache(parser: Parser) {
parser.current().children.push({ parser.current().children.push({
start, start,
end: parser.index, end: parser.index,
type: 'YieldTag' type: 'YieldTag',
}); });
} else if (parser.eat('{')) { } else if (parser.eat('{')) {
// {{{raw}}} mustache // {{{raw}}} mustache
@ -205,7 +205,7 @@ export default function mustache(parser: Parser) {
start, start,
end: parser.index, end: parser.index,
type: 'RawMustacheTag', type: 'RawMustacheTag',
expression expression,
}); });
} else { } else {
const expression = readExpression(parser); const expression = readExpression(parser);
@ -217,7 +217,7 @@ export default function mustache(parser: Parser) {
start, start,
end: parser.index, end: parser.index,
type: 'MustacheTag', type: 'MustacheTag',
expression expression,
}); });
} }

@ -4,7 +4,7 @@ import readStyle from '../read/style';
import { import {
readEventHandlerDirective, readEventHandlerDirective,
readBindingDirective, readBindingDirective,
readTransitionDirective readTransitionDirective,
} from '../read/directives'; } from '../read/directives';
import { trimStart, trimEnd } from '../../utils/trim'; import { trimStart, trimEnd } from '../../utils/trim';
import { decodeCharacterReferences } from '../utils/html'; import { decodeCharacterReferences } from '../utils/html';
@ -17,7 +17,7 @@ const validTagName = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/;
const SELF = ':Self'; const SELF = ':Self';
const metaTags = { const metaTags = {
':Window': true ':Window': true,
}; };
const specials = new Map([ const specials = new Map([
@ -25,16 +25,16 @@ const specials = new Map([
'script', 'script',
{ {
read: readScript, read: readScript,
property: 'js' property: 'js',
} },
], ],
[ [
'style', 'style',
{ {
read: readStyle, read: readStyle,
property: 'css' property: 'css',
} },
] ],
]); ]);
// based on http://developers.whatwg.org/syntax.html#syntax-tag-omission // based on http://developers.whatwg.org/syntax.html#syntax-tag-omission
@ -48,7 +48,7 @@ const disallowedContents = new Map([
'address article aside blockquote div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr main menu nav ol p pre section table ul'.split( 'address article aside blockquote div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr main menu nav ol p pre section table ul'.split(
' ' ' '
) )
) ),
], ],
['rt', new Set(['rt', 'rp'])], ['rt', new Set(['rt', 'rp'])],
['rp', new Set(['rt', 'rp'])], ['rp', new Set(['rt', 'rp'])],
@ -59,7 +59,7 @@ const disallowedContents = new Map([
['tfoot', new Set(['tbody'])], ['tfoot', new Set(['tbody'])],
['tr', new Set(['tr', 'tbody'])], ['tr', new Set(['tr', 'tbody'])],
['td', new Set(['td', 'th', 'tr'])], ['td', new Set(['td', 'th', 'tr'])],
['th', new Set(['td', 'th', 'tr'])] ['th', new Set(['td', 'th', 'tr'])],
]); ]);
function stripWhitespace(element) { function stripWhitespace(element) {
@ -92,7 +92,7 @@ export default function tag(parser: Parser) {
start, start,
end: parser.index, end: parser.index,
type: 'Comment', type: 'Comment',
data data,
}); });
return null; return null;
@ -198,7 +198,7 @@ export default function tag(parser: Parser) {
type: 'Element', type: 'Element',
name, name,
attributes, attributes,
children: [] children: [],
}; };
parser.current().children.push(element); parser.current().children.push(element);
@ -291,7 +291,7 @@ function readAttribute(parser: Parser, uniqueNames) {
start, start,
end: parser.index, end: parser.index,
type: 'Ref', type: 'Ref',
name: name.slice(4) name: name.slice(4),
}; };
} }
@ -320,7 +320,7 @@ function readAttribute(parser: Parser, uniqueNames) {
end: parser.index, end: parser.index,
type: 'Attribute', type: 'Attribute',
name, name,
value value,
}; };
} }
@ -351,9 +351,9 @@ function getShorthandValue(start: number, name: string) {
type: 'Identifier', type: 'Identifier',
start, start,
end, end,
name name,
} },
} },
]; ];
} }
@ -362,7 +362,7 @@ function readSequence(parser: Parser, done: () => boolean) {
start: parser.index, start: parser.index,
end: null, end: null,
type: 'Text', type: 'Text',
data: '' data: '',
}; };
const chunks = []; const chunks = [];
@ -397,14 +397,14 @@ function readSequence(parser: Parser, done: () => boolean) {
start: index, start: index,
end: parser.index, end: parser.index,
type: 'MustacheTag', type: 'MustacheTag',
expression expression,
}); });
currentChunk = { currentChunk = {
start: parser.index, start: parser.index,
end: null, end: null,
type: 'Text', type: 'Text',
data: '' data: '',
}; };
} else { } else {
currentChunk.data += parser.template[parser.index++]; currentChunk.data += parser.template[parser.index++];

@ -18,7 +18,7 @@ export default function text(parser: Parser) {
start, start,
end: parser.index, end: parser.index,
type: 'Text', type: 'Text',
data: decodeCharacterReferences(data) data: decodeCharacterReferences(data),
}); });
return null; return null;

@ -2030,5 +2030,5 @@ export default {
sc: 8827, sc: 8827,
wp: 8472, wp: 8472,
wr: 8768, wr: 8768,
xi: 958 xi: 958,
}; };

@ -32,7 +32,7 @@ const windows1252 = [
339, 339,
157, 157,
382, 382,
376 376,
]; ];
const entityPattern = new RegExp( const entityPattern = new RegExp(
`&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(htmlEntities).join('|')}));?`, `&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(htmlEntities).join('|')}));?`,

@ -32,7 +32,7 @@ export default function annotateWithScopes(expression: Node) {
if (node._scope) { if (node._scope) {
scope = scope.parent; scope = scope.parent;
} }
} },
}); });
return scope; return scope;
@ -99,5 +99,5 @@ const extractors = {
AssignmentPattern(names: string[], param: Node) { AssignmentPattern(names: string[], param: Node) {
extractors[param.left.type](names, param.left); extractors[param.left.type](names, param.left);
} },
}; };

@ -22,5 +22,5 @@ export default new Set([
'RegExp', 'RegExp',
'Set', 'Set',
'String', 'String',
'undefined' 'undefined',
]); ]);

@ -17,7 +17,7 @@ export const validNamespaces = [
svg, svg,
xlink, xlink,
xml, xml,
xmlns xmlns,
]; ];
export default { html, mathml, svg, xlink, xml, xmlns }; export default { html, mathml, svg, xlink, xml, xmlns };

@ -2,12 +2,12 @@ import { Node } from '../interfaces';
const keys = { const keys = {
ObjectExpression: 'properties', ObjectExpression: 'properties',
Program: 'body' Program: 'body',
}; };
const offsets = { const offsets = {
ObjectExpression: [1, -1], ObjectExpression: [1, -1],
Program: [0, 0] Program: [0, 0],
}; };
export function removeNode(code, parent: Node, node: Node) { export function removeNode(code, parent: Node, node: Node) {

@ -46,7 +46,7 @@ const reservedNames = new Set([
'void', 'void',
'while', 'while',
'with', 'with',
'yield' 'yield',
]); ]);
// prevent e.g. `{{#each states as state}}` breaking // prevent e.g. `{{#each states as state}}` breaking

@ -11,7 +11,7 @@ const validBindings = [
'outerWidth', 'outerWidth',
'outerHeight', 'outerHeight',
'scrollX', 'scrollX',
'scrollY' 'scrollY',
]; ];
export default function validateWindow(validator: Validator, node: Node) { export default function validateWindow(validator: Validator, node: Node) {

@ -64,7 +64,7 @@ export class Validator {
loc: { line: line + 1, column }, loc: { line: line + 1, column },
pos, pos,
filename: this.filename, filename: this.filename,
toString: () => `${message} (${line + 1}:${column})\n${frame}` toString: () => `${message} (${line + 1}:${column})\n${frame}`,
}); });
} }
} }
@ -87,14 +87,14 @@ export default function validate(
onwarn({ onwarn({
message, message,
filename, filename,
toString: () => message toString: () => message,
}); });
} }
const validator = new Validator(parsed, source, { const validator = new Validator(parsed, source, {
onwarn, onwarn,
name, name,
filename filename,
}); });
if (parsed.js) { if (parsed.js) {

@ -5,7 +5,7 @@ import { Node } from '../../../interfaces';
const isFunctionExpression = new Set([ const isFunctionExpression = new Set([
'FunctionExpression', 'FunctionExpression',
'ArrowFunctionExpression' 'ArrowFunctionExpression',
]); ]);
export default function computed(validator: Validator, prop: Node) { export default function computed(validator: Validator, prop: Node) {

@ -57,7 +57,7 @@ export default function helpers(validator: Validator, prop: Node) {
if (/^Function/.test(node.type)) { if (/^Function/.test(node.type)) {
lexicalDepth -= 1; lexicalDepth -= 1;
} }
} },
}); });
if (prop.value.params.length === 0 && !usesArguments) { if (prop.value.params.length === 0 && !usesArguments) {

@ -23,5 +23,5 @@ export default {
components, components,
events, events,
namespace, namespace,
transitions transitions,
}; };

@ -26,7 +26,7 @@ export default function usesThisOrArguments(node: Node) {
) { ) {
result = true; result = true;
} }
} },
}); });
return result; return result;

@ -179,7 +179,7 @@ export default function FuzzySet(
matchScore = matches[matchIndex]; matchScore = matches[matchIndex];
results.push([ results.push([
matchScore / (vectorNormal * items[matchIndex][0]), matchScore / (vectorNormal * items[matchIndex][0]),
items[matchIndex][1] items[matchIndex][1],
]); ]);
} }
function sortDescending(a, b) { function sortDescending(a, b) {
@ -200,7 +200,7 @@ export default function FuzzySet(
for (let i = 0; i < endIndex; ++i) { for (let i = 0; i < endIndex; ++i) {
newResults.push([ newResults.push([
_distance(results[i][1], normalizedValue), _distance(results[i][1], normalizedValue),
results[i][1] results[i][1],
]); ]);
} }
results = newResults; results = newResults;

Loading…
Cancel
Save