diff --git a/.gitattributes b/.gitattributes index eb49e7815619..727f1cc68767 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ *.svelte linguist-language=HTML +tsconfig*.json linguist-language=javascript diff --git a/package.json b/package.json index 9c1ca2b15b5a..8742fc27c67c 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,8 @@ "posttest": "agadoo internal/index.mjs", "prepublishOnly": "export PUBLISH=true && npm test && npm run create-stubs", "create-stubs": "node scripts/create-stubs.js", - "tsd": "tsc -p . --emitDeclarationOnly", - "typecheck": "tsc -p . --noEmit", + "tsd": "tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly", + "typecheck": "tsc -p src/compiler --noEmit && tsc -p src/runtime --noEmit", "lint": "eslint \"{src,test}/**/*.{ts,js}\"" }, "repository": { diff --git a/src/compiler/compile/index.ts b/src/compiler/compile/index.ts index 3f4a3eeb3225..f75a4390ec1e 100644 --- a/src/compiler/compile/index.ts +++ b/src/compiler/compile/index.ts @@ -1,4 +1,4 @@ -import { assign } from '../../runtime/internal/index'; +import { assign } from '../../runtime/internal/utils'; import Stats from '../Stats'; import parse from '../parse/index'; import render_dom from './render-dom/index'; diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json new file mode 100644 index 000000000000..7043efa7ddd1 --- /dev/null +++ b/src/compiler/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["."], + + "compilerOptions": { + "lib": ["es2017", "webworker"] + + // TODO: remove mocha types from the whole project + // "types": ["node", "estree"] + } +} diff --git a/src/runtime/internal/animations.ts b/src/runtime/internal/animations.ts index 77c86aff0e3d..16aa4065552d 100644 --- a/src/runtime/internal/animations.ts +++ b/src/runtime/internal/animations.ts @@ -1,4 +1,5 @@ -import { identity as linear, noop, now } from './utils'; +import { identity as linear, noop } from './utils'; +import { now } from "./environment"; import { loop } from './loop'; import { create_rule, delete_rule } from './style_manager'; import { AnimationConfig } from '../animate'; diff --git a/src/runtime/internal/environment.ts b/src/runtime/internal/environment.ts new file mode 100644 index 000000000000..02cb05f30a19 --- /dev/null +++ b/src/runtime/internal/environment.ts @@ -0,0 +1,18 @@ +import { noop } from './utils'; + +export const is_client = typeof window !== 'undefined'; + +export let now: () => number = is_client + ? () => window.performance.now() + : () => Date.now(); + +export let raf = is_client ? requestAnimationFrame : noop; + +// used internally for testing +export function set_now(fn) { + now = fn; +} + +export function set_raf(fn) { + raf = fn; +} diff --git a/src/runtime/internal/index.ts b/src/runtime/internal/index.ts index 6487f04525f3..d9d95541ebc3 100644 --- a/src/runtime/internal/index.ts +++ b/src/runtime/internal/index.ts @@ -1,6 +1,7 @@ export * from './animations'; export * from './await-block'; export * from './dom'; +export * from './environment'; export * from './keyed-each'; export * from './lifecycle'; export * from './loop'; diff --git a/src/runtime/internal/loop.ts b/src/runtime/internal/loop.ts index cc6161105d48..0ab89d41351f 100644 --- a/src/runtime/internal/loop.ts +++ b/src/runtime/internal/loop.ts @@ -1,4 +1,4 @@ -import { now, raf } from './utils'; +import { now, raf } from "./environment"; export interface Task { abort(): void; promise: Promise } diff --git a/src/runtime/internal/style_manager.ts b/src/runtime/internal/style_manager.ts index 2721200627f2..ceb1b000eb53 100644 --- a/src/runtime/internal/style_manager.ts +++ b/src/runtime/internal/style_manager.ts @@ -1,5 +1,5 @@ import { element } from './dom'; -import { raf } from './utils'; +import { raf } from "./environment"; let stylesheet; let active = 0; diff --git a/src/runtime/internal/transitions.ts b/src/runtime/internal/transitions.ts index 5591ca1d5127..80c76ffec5d2 100644 --- a/src/runtime/internal/transitions.ts +++ b/src/runtime/internal/transitions.ts @@ -1,4 +1,5 @@ -import { identity as linear, is_function, noop, now, run_all } from './utils'; +import { identity as linear, is_function, noop, run_all } from './utils'; +import { now } from "./environment"; import { loop } from './loop'; import { create_rule, delete_rule } from './style_manager'; import { custom_event } from './dom'; diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 152c0e79b02b..7fdf9591f49f 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -89,20 +89,3 @@ export function once(fn) { fn.call(this, ...args); } } - -const is_client = typeof window !== 'undefined'; - -export let now: () => number = is_client - ? () => window.performance.now() - : () => Date.now(); - -export let raf = is_client ? requestAnimationFrame : noop; - -// used internally for testing -export function set_now(fn) { - now = fn; -} - -export function set_raf(fn) { - raf = fn; -} diff --git a/src/runtime/tsconfig.json b/src/runtime/tsconfig.json new file mode 100644 index 000000000000..ed24bd727ef4 --- /dev/null +++ b/src/runtime/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["."], + + "compilerOptions": { + "lib": ["es2015", "dom", "dom.iterable"], + "target": "es2015", + "types": [], + + "baseUrl": ".", + "paths": { + "svelte/*": ["*"] + } + } +} diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 000000000000..61d7ba79ab2e --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.base.json", + "include": ["."], + + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "noEmit": true + } +} diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 000000000000..687cec479439 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "rootDir": "src", + + // target node v8+ (https://node.green/) + // the only missing feature is Array.prototype.values + "lib": ["es2017"], + "target": "es2017", + + "declaration": true, + "declarationDir": "types", + + "noEmitOnError": true, + "noErrorTruncation": true, + + // rollup takes care of these + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true, + + // TODO: error all the things + //"strict": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true + } +} diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 07bc24acaf03..000000000000 --- a/tsconfig.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "compilerOptions": { - "target": "es2015", - "module": "es6", - "declaration": true, - "declarationDir": "types", - "noImplicitThis": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noEmitOnError": true, - "lib": [ - "es5", - "es6", - "dom", - "es2015" - ], - "importHelpers": true, - "moduleResolution": "node", - "baseUrl": ".", - "paths": { - "svelte/internal": ["./src/runtime/internal/index"], - "svelte/easing": ["./src/runtime/easing/index"], - "svelte/motion": ["./src/runtime/motion/index"], - "svelte/store": ["./src/runtime/store/index"] - }, - "typeRoots": [ - "node_modules/@types" - ] - }, - "include": [ - "src/**/*" - ] -}