more TS fixes

pull/736/head
Rich Harris 8 years ago
parent bd9c59aa5a
commit aa59dafb81

@ -16,6 +16,7 @@ import DomBlock from './dom/Block';
import SsrBlock from './server-side-rendering/Block';
import Stylesheet from '../css/Stylesheet';
import { Node, GenerateOptions, Parsed, CompileOptions } from '../interfaces';
import { Computation, TemplateProperties } from './interfaces';
const test = typeof global !== 'undefined' && global.__svelte_test;
@ -26,12 +27,18 @@ export default class Generator {
name: string;
options: CompileOptions;
defaultExport: Node[];
imports: Node[];
helpers: Set<string>;
components: Set<string>;
events: Set<string>;
transitions: Set<string>;
importedComponents: Map<string, string>;
namespace: string;
hasComponents: boolean;
hasJs: boolean;
computations: Computation[];
templateProperties: TemplateProperties;
code: MagicString;
@ -379,9 +386,9 @@ export default class Generator {
return alias;
}
getUniqueNameMaker(params) {
getUniqueNameMaker(params: string[]) {
const localUsedNames = new Set(params);
return name => {
return (name: string) => {
if (test) name = `${name}$`;
let alias = name;
for (
@ -402,8 +409,8 @@ export default class Generator {
const { js } = this.parsed;
const imports = this.imports;
const computations = [];
const templateProperties = {};
const computations: Computation[] = [];
const templateProperties: TemplateProperties = {};
let namespace = null;
let hasJs = !!js;
@ -459,7 +466,7 @@ export default class Generator {
const visited = new Set();
function visit(key) {
function visit(key: string) {
if (!dependencies.has(key)) return; // not a computation
if (visited.has(key)) return;

@ -317,7 +317,7 @@ export default function dom(
let scope = annotateWithScopes(expression);
walk(expression, {
enter(node, parent) {
enter(node: Node, parent: Node) {
if (node._scope) scope = node._scope;
if (
@ -337,7 +337,7 @@ export default function dom(
}
},
leave(node) {
leave(node: Node) {
if (node._scope) scope = scope.parent;
},
});

@ -1,5 +1,5 @@
export interface State {
name: string;
name?: string;
namespace: string;
parentNode: string;
parentNodes: string;

@ -0,0 +1,23 @@
import { Node } from '../interfaces';
export interface Computation {
key: string;
deps: string[]
}
export interface TemplateProperties {
computed?: Node;
components?: Node;
data?: Node;
events?: Node;
helpers?: Node;
methods?: Node;
namespace?: Node;
oncreate?: Node;
ondestroy?: Node;
transitions?: Node;
// TODO remove in v2
onrender?: Node;
onteardown?: Node;
}

@ -34,8 +34,10 @@ export interface Warning {
toString: () => string;
}
export type ModuleFormat = 'es' | 'amd' | 'cjs' | 'iife' | 'umd' | 'eval';
export interface CompileOptions {
format?: string;
format?: ModuleFormat;
name?: string;
filename?: string;
generate?: string;
@ -56,8 +58,6 @@ export interface CompileOptions {
onwarn?: (warning: Warning) => void;
}
export type ModuleFormat = 'es' | 'amd' | 'cjs' | 'iife' | 'umd' | 'eval';
export interface GenerateOptions {
name: string;
format: ModuleFormat;

@ -2,7 +2,7 @@ import { parseExpressionAt } from 'acorn';
import spaces from '../../utils/spaces';
import { Parser } from '../index';
function readExpression(parser: Parser, start: number, quoteMark) {
function readExpression(parser: Parser, start: number, quoteMark: string|null) {
let str = '';
let escaped = false;

@ -1,10 +1,11 @@
import { parse } from 'acorn';
import spaces from '../../utils/spaces';
import { Parser } from '../index';
import { Node } from '../../interfaces';
const scriptClosingTag = '</script>';
export default function readScript(parser: Parser, start: number, attributes) {
export default function readScript(parser: Parser, start: number, attributes: Node[]) {
const scriptStart = parser.index;
const scriptEnd = parser.template.indexOf(scriptClosingTag, scriptStart);

@ -1,8 +1,9 @@
import parse from 'css-tree/lib/parser/index.js';
import walk from 'css-tree/lib/utils/walk.js';
import { Parser } from '../index';
import { Node } from '../../interfaces';
export default function readStyle(parser: Parser, start: number, attributes) {
export default function readStyle(parser: Parser, start: number, attributes: Node[]) {
const contentStart = parser.index;
const styles = parser.readUntil(/<\/style>/);
const contentEnd = parser.index;
@ -23,7 +24,7 @@ export default function readStyle(parser: Parser, start: number, attributes) {
}
// tidy up AST
walk.all(ast, node => {
walk.all(ast, (node: Node) => {
if (node.loc) {
node.start = node.loc.start.offset;
node.end = node.loc.end.offset;

@ -6,7 +6,7 @@ import { Node } from '../../interfaces';
const validIdentifier = /[a-zA-Z_$][a-zA-Z0-9_$]*/;
function trimWhitespace(block, trimBefore, trimAfter) {
function trimWhitespace(block: Node, trimBefore: boolean, trimAfter: boolean) {
const firstChild = block.children[0];
const lastChild = block.children[block.children.length - 1];
@ -220,6 +220,4 @@ export default function mustache(parser: Parser) {
expression,
});
}
return null;
}

@ -78,7 +78,7 @@ export default function tag(parser: Parser) {
data,
});
return null;
return;
}
const isClosingTag = parser.eat('/');
@ -133,7 +133,7 @@ export default function tag(parser: Parser) {
parent.end = parser.index;
parser.stack.pop();
return null;
return;
} else if (disallowedContents.has(parent.name)) {
// can this be a child of the parent element, or does it implicitly
// close it, like `<li>one<li>two`?
@ -200,8 +200,6 @@ export default function tag(parser: Parser) {
// don't push self-closing elements onto the stack
parser.stack.push(element);
}
return null;
}
function readTagName(parser: Parser) {
@ -242,7 +240,7 @@ function readTagName(parser: Parser) {
return name;
}
function readAttribute(parser: Parser, uniqueNames) {
function readAttribute(parser: Parser, uniqueNames: Set<string>) {
const start = parser.index;
let name = parser.readUntil(/(\s|=|\/|>)/);

@ -20,6 +20,4 @@ export default function text(parser: Parser) {
type: 'Text',
data: decodeCharacterReferences(data),
});
return null;
}

Loading…
Cancel
Save