fix various TS complaints

pull/941/head
Rich Harris 8 years ago
parent ffe232e04a
commit 4e4ef173d6

@ -0,0 +1 @@
export const test = typeof process !== 'undefined' && process.env.TEST;

@ -322,7 +322,7 @@ export default class Stylesheet {
leave: (node: Node) => { leave: (node: Node) => {
if (node.type === 'Rule' || node.type === 'Atrule') stack.pop(); if (node.type === 'Rule' || node.type === 'Atrule') stack.pop();
if (node.type === 'Atrule') currentAtrule = stack[stack.length - 1]; if (node.type === 'Atrule') currentAtrule = <Atrule>stack[stack.length - 1];
} }
}); });
} else { } else {

@ -16,10 +16,9 @@ import clone from '../utils/clone';
import DomBlock from './dom/Block'; import DomBlock from './dom/Block';
import SsrBlock from './server-side-rendering/Block'; import SsrBlock from './server-side-rendering/Block';
import Stylesheet from '../css/Stylesheet'; import Stylesheet from '../css/Stylesheet';
import { test } from '../config';
import { Node, GenerateOptions, Parsed, CompileOptions, CustomElementOptions } from '../interfaces'; import { Node, GenerateOptions, Parsed, CompileOptions, CustomElementOptions } from '../interfaces';
const test = typeof global !== 'undefined' && global.__svelte_test;
interface Computation { interface Computation {
key: string; key: string;
deps: string[] deps: string[]

@ -202,7 +202,7 @@ export default class Block {
} }
// minor hack we need to ensure that any {{{triples}}} are detached first // minor hack we need to ensure that any {{{triples}}} are detached first
this.builders.unmount.addBlockAtStart(this.builders.detachRaw); this.builders.unmount.addBlockAtStart(this.builders.detachRaw.toString());
const properties = new CodeBuilder(); const properties = new CodeBuilder();

@ -14,11 +14,9 @@ import Generator from '../Generator';
import Stylesheet from '../../css/Stylesheet'; import Stylesheet from '../../css/Stylesheet';
import preprocess from './preprocess'; import preprocess from './preprocess';
import Block from './Block'; import Block from './Block';
import { version } from '../../../package.json'; import { test } from '../../config';
import { Parsed, CompileOptions, Node } from '../../interfaces'; import { Parsed, CompileOptions, Node } from '../../interfaces';
const test = typeof global !== 'undefined' && global.__svelte_test;
export class DomGenerator extends Generator { export class DomGenerator extends Generator {
blocks: (Block|string)[]; blocks: (Block|string)[];
readonly: Set<string>; readonly: Set<string>;
@ -167,9 +165,9 @@ export default function dom(
builder.addBlock(block.toString()); builder.addBlock(block.toString());
}); });
const sharedPath = options.shared === true const sharedPath: string = options.shared === true
? 'svelte/shared.js' ? 'svelte/shared.js'
: options.shared; : options.shared || '';
const prototypeBase = const prototypeBase =
`${name}.prototype` + `${name}.prototype` +
@ -444,7 +442,7 @@ export default function dom(
); );
return generator.generate(result, options, { return generator.generate(result, options, {
banner: `/* ${filename ? `${filename} ` : ``}generated by Svelte v${version} */`, banner: `/* ${filename ? `${filename} ` : ``}generated by Svelte v__VERSION__ */`,
sharedPath, sharedPath,
helpers, helpers,
name, name,

@ -28,7 +28,7 @@ export default function visitWindow(
node: Node node: Node
) { ) {
const events = {}; const events = {};
const bindings = {}; const bindings: Record<string, string> = {};
node.attributes.forEach((attribute: Node) => { node.attributes.forEach((attribute: Node) => {
if (attribute.type === 'EventHandler') { if (attribute.type === 'EventHandler') {

@ -26,7 +26,7 @@ export default function visitEachBlock(
contextDependencies.set(node.context, dependencies); contextDependencies.set(node.context, dependencies);
if (node.destructuredContexts) { if (node.destructuredContexts) {
for (const i = 0; i < node.destructuredContexts.length; i++) { for (let i = 0; i < node.destructuredContexts.length; i += 1) {
contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`); contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`);
contextDependencies.set(node.destructuredContexts[i], dependencies); contextDependencies.set(node.destructuredContexts[i], dependencies);
} }

@ -65,7 +65,7 @@ export interface GenerateOptions {
name: string; name: string;
format: ModuleFormat; format: ModuleFormat;
banner?: string; banner?: string;
sharedPath?: string | boolean; sharedPath?: string;
helpers?: { name: string, alias: string }[]; helpers?: { name: string, alias: string }[];
} }

@ -23,6 +23,8 @@ interface ParserOptions {
filename?: string; filename?: string;
} }
type ParserState = (parser: Parser) => (ParserState | void);
export class Parser { export class Parser {
readonly template: string; readonly template: string;
readonly filename?: string; readonly filename?: string;
@ -59,7 +61,7 @@ export class Parser {
this.stack.push(this.html); this.stack.push(this.html);
let state = fragment; let state: ParserState = fragment;
while (this.index < this.template.length) { while (this.index < this.template.length) {
state = state(this) || fragment; state = state(this) || fragment;
@ -94,7 +96,7 @@ export class Parser {
return this.stack[this.stack.length - 1]; return this.stack[this.stack.length - 1];
} }
acornError(err: Error) { acornError(err: any) {
this.error(err.message.replace(/ \(\d+:\d+\)$/, ''), err.pos); this.error(err.message.replace(/ \(\d+:\d+\)$/, ''), err.pos);
} }

@ -1,6 +1,5 @@
{ {
"compilerOptions": { "compilerOptions": {
"noImplicitAny": true,
"diagnostics": true, "diagnostics": true,
"noImplicitThis": true, "noImplicitThis": true,
"noEmitOnError": true, "noEmitOnError": true,

Loading…
Cancel
Save