From 25aa02c4fd0702252530f0aa76e6a330a74eb8df Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 6 May 2017 19:43:33 -0400 Subject: [PATCH 01/14] start converting to typescript --- package.json | 4 +++- rollup/rollup.config.main.js | 10 ++++------ rollup/rollup.config.ssr.js | 4 ++-- src/{index.js => index.ts} | 0 src/server-side-rendering/register.js | 2 +- tsconfig.json | 10 ++++++++++ yarn.lock | 28 ++++++++++++++++++++++++++- 7 files changed, 47 insertions(+), 11 deletions(-) rename src/{index.js => index.ts} (100%) create mode 100644 tsconfig.json diff --git a/package.json b/package.json index aa7242cc823d..04232c871c81 100644 --- a/package.json +++ b/package.json @@ -74,9 +74,11 @@ "rollup-plugin-commonjs": "^7.0.0", "rollup-plugin-json": "^2.1.0", "rollup-plugin-node-resolve": "^2.0.0", + "rollup-plugin-typescript": "^0.8.1", "rollup-watch": "^3.2.2", "source-map": "^0.5.6", - "source-map-support": "^0.4.8" + "source-map-support": "^0.4.8", + "typescript": "^2.3.2" }, "nyc": { "include": [ diff --git a/rollup/rollup.config.main.js b/rollup/rollup.config.main.js index c05b9911cf21..f95c96d4e8ae 100644 --- a/rollup/rollup.config.main.js +++ b/rollup/rollup.config.main.js @@ -1,10 +1,10 @@ import nodeResolve from 'rollup-plugin-node-resolve'; import commonjs from 'rollup-plugin-commonjs'; import json from 'rollup-plugin-json'; -import buble from 'rollup-plugin-buble'; +import typescript from 'rollup-plugin-typescript'; export default { - entry: 'src/index.js', + entry: 'src/index.ts', moduleName: 'svelte', targets: [ { dest: 'compiler/svelte.js', format: 'umd' } @@ -13,12 +13,10 @@ export default { nodeResolve({ jsnext: true, module: true }), commonjs(), json(), - buble({ + typescript({ include: 'src/**', exclude: 'src/shared/**', - target: { - node: 4 - } + typescript: require( 'typescript' ) }) ], sourceMap: true diff --git a/rollup/rollup.config.ssr.js b/rollup/rollup.config.ssr.js index 38caf3ece401..e44315af38c8 100644 --- a/rollup/rollup.config.ssr.js +++ b/rollup/rollup.config.ssr.js @@ -20,9 +20,9 @@ export default { } }) ], - external: [ path.resolve( 'src/index.js' ), 'fs', 'path' ], + external: [ path.resolve( 'src/index.ts' ), 'fs', 'path' ], paths: { - [ path.resolve( 'src/index.js' ) ]: '../compiler/svelte.js' + [ path.resolve( 'src/index.ts' ) ]: '../compiler/svelte.js' }, sourceMap: true }; diff --git a/src/index.js b/src/index.ts similarity index 100% rename from src/index.js rename to src/index.ts diff --git a/src/server-side-rendering/register.js b/src/server-side-rendering/register.js index 95c2a63fad12..3a1ca580301c 100644 --- a/src/server-side-rendering/register.js +++ b/src/server-side-rendering/register.js @@ -1,6 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; -import { compile } from '../index.js'; +import { compile } from '../index.ts'; function capitalise ( name ) { return name[0].toUpperCase() + name.slice( 1 ); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000000..970ff6a19704 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "types" : ["node"], + "noImplicitAny": true, + "diagnostics": true, + "noImplicitThis": true, + "noEmitOnError": true + }, + "target": "ES5" +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index ba7fd4c73f55..0304d30ae644 100644 --- a/yarn.lock +++ b/yarn.lock @@ -811,6 +811,10 @@ commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" +compare-versions@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-2.0.1.tgz#1edc1f93687fd97a325c59f55e45a07db106aca6" + concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" @@ -2477,7 +2481,17 @@ rollup-plugin-node-resolve@^2.0.0: builtin-modules "^1.1.0" resolve "^1.1.6" -rollup-pluginutils@^1.5.0, rollup-pluginutils@^1.5.2: +rollup-plugin-typescript@^0.8.1: + version "0.8.1" + resolved "https://registry.yarnpkg.com/rollup-plugin-typescript/-/rollup-plugin-typescript-0.8.1.tgz#2ff7eecc21cf6bb2b43fc27e5b688952ce71924a" + dependencies: + compare-versions "2.0.1" + object-assign "^4.0.1" + rollup-pluginutils "^1.3.1" + tippex "^2.1.1" + typescript "^1.8.9" + +rollup-pluginutils@^1.3.1, rollup-pluginutils@^1.5.0, rollup-pluginutils@^1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408" dependencies: @@ -2733,6 +2747,10 @@ through@^2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" +tippex@^2.1.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/tippex/-/tippex-2.3.1.tgz#a2fd5b7087d7cbfb20c9806a6c16108c2c0fafda" + to-fast-properties@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.2.tgz#f3f5c0c3ba7299a7ef99427e44633257ade43320" @@ -2775,6 +2793,14 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" +typescript@^1.8.9: + version "1.8.10" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-1.8.10.tgz#b475d6e0dff0bf50f296e5ca6ef9fbb5c7320f1e" + +typescript@^2.3.2: + version "2.3.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.2.tgz#f0f045e196f69a72f06b25fd3bd39d01c3ce9984" + uglify-js@^2.6: version "2.8.22" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.22.tgz#d54934778a8da14903fa29a326fb24c0ab51a1a0" From 366c490bcc869989dcf39d565063642df4872d2c Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 6 May 2017 21:54:28 -0400 Subject: [PATCH 02/14] switch a few more files over --- src/index.ts | 2 +- src/parse/{index.js => index.ts} | 4 ++-- src/parse/read/{directives.js => directives.ts} | 0 src/parse/read/{expression.js => expression.ts} | 0 src/parse/read/{script.js => script.ts} | 0 src/parse/read/{style.js => style.ts} | 0 src/parse/state/{fragment.js => fragment.ts} | 6 +++--- src/parse/state/{mustache.js => mustache.ts} | 2 +- src/parse/state/{tag.js => tag.ts} | 10 +++++----- src/parse/state/{text.js => text.ts} | 2 +- src/parse/utils/{entities.js => entities.ts} | 0 src/parse/utils/{hash.js => hash.ts} | 0 src/parse/utils/{html.js => html.ts} | 2 +- tsconfig.json | 16 ++++++++-------- 14 files changed, 22 insertions(+), 22 deletions(-) rename src/parse/{index.js => index.ts} (98%) rename src/parse/read/{directives.js => directives.ts} (100%) rename src/parse/read/{expression.js => expression.ts} (100%) rename src/parse/read/{script.js => script.ts} (100%) rename src/parse/read/{style.js => style.ts} (100%) rename src/parse/state/{fragment.js => fragment.ts} (63%) rename src/parse/state/{mustache.js => mustache.ts} (98%) rename src/parse/state/{tag.js => tag.ts} (97%) rename src/parse/state/{text.js => text.ts} (86%) rename src/parse/utils/{entities.js => entities.ts} (100%) rename src/parse/utils/{hash.js => hash.ts} (100%) rename src/parse/utils/{html.js => html.ts} (98%) diff --git a/src/index.ts b/src/index.ts index f5b013940d64..b9ce974b8434 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import parse from './parse/index.js'; +import parse from './parse/index.ts'; import validate from './validate/index.js'; import generate from './generators/dom/index.js'; import generateSSR from './generators/server-side-rendering/index.js'; diff --git a/src/parse/index.js b/src/parse/index.ts similarity index 98% rename from src/parse/index.js rename to src/parse/index.ts index 7ea7be222f97..fbfa11e4fa23 100644 --- a/src/parse/index.js +++ b/src/parse/index.ts @@ -1,9 +1,9 @@ import { locate } from 'locate-character'; -import fragment from './state/fragment.js'; +import fragment from './state/fragment.ts'; import { whitespace } from '../utils/patterns.js'; import { trimStart, trimEnd } from '../utils/trim.js'; import getCodeFrame from '../utils/getCodeFrame.js'; -import hash from './utils/hash.js'; +import hash from './utils/hash.ts'; function ParseError ( message, template, index, filename ) { const { line, column } = locate( template, index ); diff --git a/src/parse/read/directives.js b/src/parse/read/directives.ts similarity index 100% rename from src/parse/read/directives.js rename to src/parse/read/directives.ts diff --git a/src/parse/read/expression.js b/src/parse/read/expression.ts similarity index 100% rename from src/parse/read/expression.js rename to src/parse/read/expression.ts diff --git a/src/parse/read/script.js b/src/parse/read/script.ts similarity index 100% rename from src/parse/read/script.js rename to src/parse/read/script.ts diff --git a/src/parse/read/style.js b/src/parse/read/style.ts similarity index 100% rename from src/parse/read/style.js rename to src/parse/read/style.ts diff --git a/src/parse/state/fragment.js b/src/parse/state/fragment.ts similarity index 63% rename from src/parse/state/fragment.js rename to src/parse/state/fragment.ts index 100e28687d48..af9d7eb8618b 100644 --- a/src/parse/state/fragment.js +++ b/src/parse/state/fragment.ts @@ -1,6 +1,6 @@ -import tag from './tag.js'; -import mustache from './mustache.js'; -import text from './text.js'; +import tag from './tag.ts'; +import mustache from './mustache.ts'; +import text from './text.ts'; export default function fragment ( parser ) { if ( parser.match( '<' ) ) { diff --git a/src/parse/state/mustache.js b/src/parse/state/mustache.ts similarity index 98% rename from src/parse/state/mustache.js rename to src/parse/state/mustache.ts index 9a9dd33886ab..6eb3431aa09a 100644 --- a/src/parse/state/mustache.js +++ b/src/parse/state/mustache.ts @@ -1,4 +1,4 @@ -import readExpression from '../read/expression.js'; +import readExpression from '../read/expression.ts'; import { whitespace } from '../../utils/patterns.js'; import { trimStart, trimEnd } from '../../utils/trim.js'; diff --git a/src/parse/state/tag.js b/src/parse/state/tag.ts similarity index 97% rename from src/parse/state/tag.js rename to src/parse/state/tag.ts index 475043f311c2..4fbc9c9767a7 100644 --- a/src/parse/state/tag.js +++ b/src/parse/state/tag.ts @@ -1,9 +1,9 @@ -import readExpression from '../read/expression.js'; -import readScript from '../read/script.js'; -import readStyle from '../read/style.js'; -import { readEventHandlerDirective, readBindingDirective, readTransitionDirective } from '../read/directives.js'; +import readExpression from '../read/expression.ts'; +import readScript from '../read/script.ts'; +import readStyle from '../read/style.ts'; +import { readEventHandlerDirective, readBindingDirective, readTransitionDirective } from '../read/directives.ts'; import { trimStart, trimEnd } from '../../utils/trim.js'; -import { decodeCharacterReferences } from '../utils/html.js'; +import { decodeCharacterReferences } from '../utils/html.ts'; import isVoidElementName from '../../utils/isVoidElementName.js'; const validTagName = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/; diff --git a/src/parse/state/text.js b/src/parse/state/text.ts similarity index 86% rename from src/parse/state/text.js rename to src/parse/state/text.ts index ee42dd25e3bc..eec33ac996c4 100644 --- a/src/parse/state/text.js +++ b/src/parse/state/text.ts @@ -1,4 +1,4 @@ -import { decodeCharacterReferences } from '../utils/html.js'; +import { decodeCharacterReferences } from '../utils/html.ts'; export default function text ( parser ) { const start = parser.index; diff --git a/src/parse/utils/entities.js b/src/parse/utils/entities.ts similarity index 100% rename from src/parse/utils/entities.js rename to src/parse/utils/entities.ts diff --git a/src/parse/utils/hash.js b/src/parse/utils/hash.ts similarity index 100% rename from src/parse/utils/hash.js rename to src/parse/utils/hash.ts diff --git a/src/parse/utils/html.js b/src/parse/utils/html.ts similarity index 98% rename from src/parse/utils/html.js rename to src/parse/utils/html.ts index 634fd090edd3..9fdd84aefb55 100644 --- a/src/parse/utils/html.js +++ b/src/parse/utils/html.ts @@ -1,4 +1,4 @@ -import htmlEntities from './entities.js'; +import htmlEntities from './entities.ts'; const windows1252 = [ 8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 141, 381, 143, 144, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 157, 382, 376 ]; const entityPattern = new RegExp( `&(#?(?:x[\\w\\d]+|\\d+|${Object.keys( htmlEntities ).join( '|' )}));?`, 'g' ); diff --git a/tsconfig.json b/tsconfig.json index 970ff6a19704..bde384bdc397 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,10 @@ { - "compilerOptions": { - "types" : ["node"], - "noImplicitAny": true, - "diagnostics": true, - "noImplicitThis": true, - "noEmitOnError": true - }, - "target": "ES5" + "compilerOptions": { + "types" : ["node"], + "noImplicitAny": true, + "diagnostics": true, + "noImplicitThis": true, + "noEmitOnError": true + }, + "target": "ES5" } \ No newline at end of file From 1c5e6e7430aa31a3a0193a9577b742a456649965 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 6 May 2017 22:21:16 -0400 Subject: [PATCH 03/14] rename all (almost) .js files --- rename.js | 9 +++++ src/generators/{Generator.js => Generator.ts} | 22 ++++++------ src/generators/dom/{Block.js => Block.ts} | 2 +- src/generators/dom/{index.js => index.ts} | 14 ++++---- .../dom/{preprocess.js => preprocess.ts} | 4 +-- src/generators/dom/shared.ts | 35 +++++++++++++++++++ src/generators/dom/{visit.js => visit.ts} | 2 +- .../Component/{Attribute.js => Attribute.ts} | 0 .../Component/{Binding.js => Binding.ts} | 4 +-- .../Component/{Component.js => Component.ts} | 12 +++---- .../{EventHandler.js => EventHandler.ts} | 0 .../dom/visitors/Component/{Ref.js => Ref.ts} | 0 .../visitors/{EachBlock.js => EachBlock.ts} | 2 +- .../Element/{Attribute.js => Attribute.ts} | 4 +-- .../Element/{Binding.js => Binding.ts} | 6 ++-- .../Element/{Element.js => Element.ts} | 16 ++++----- .../{EventHandler.js => EventHandler.ts} | 2 +- .../dom/visitors/Element/{Ref.js => Ref.ts} | 0 .../{addTransitions.js => addTransitions.ts} | 0 ...uteValue.js => getStaticAttributeValue.ts} | 0 .../visitors/Element/{lookup.js => lookup.ts} | 0 .../Element/meta/{Window.js => Window.ts} | 2 +- .../dom/visitors/{IfBlock.js => IfBlock.ts} | 2 +- .../{MustacheTag.js => MustacheTag.ts} | 0 .../{RawMustacheTag.js => RawMustacheTag.ts} | 0 .../dom/visitors/{Text.js => Text.ts} | 0 .../dom/visitors/{YieldTag.js => YieldTag.ts} | 0 src/generators/dom/visitors/index.js | 17 --------- src/generators/dom/visitors/index.ts | 17 +++++++++ .../binding/{getSetter.js => getSetter.ts} | 0 .../{Block.js => Block.ts} | 2 +- .../{index.js => index.ts} | 6 ++-- .../{visit.js => visit.ts} | 2 +- .../visitors/{Comment.js => Comment.ts} | 0 .../visitors/{Component.js => Component.ts} | 4 +-- .../visitors/{EachBlock.js => EachBlock.ts} | 2 +- .../visitors/{Element.js => Element.ts} | 8 ++--- .../visitors/{IfBlock.js => IfBlock.ts} | 2 +- .../{MustacheTag.js => MustacheTag.ts} | 0 .../{RawMustacheTag.js => RawMustacheTag.ts} | 0 .../visitors/{Text.js => Text.ts} | 0 .../visitors/{YieldTag.js => YieldTag.ts} | 0 .../server-side-rendering/visitors/index.js | 19 ---------- .../server-side-rendering/visitors/index.ts | 19 ++++++++++ .../visitors/meta/{Window.js => Window.ts} | 0 .../shared/{processCss.js => processCss.ts} | 0 .../utils/{getGlobals.js => getGlobals.ts} | 0 .../shared/utils/{getIntro.js => getIntro.ts} | 2 +- .../shared/utils/{getOutro.js => getOutro.ts} | 2 +- .../shared/utils/{walkHtml.js => walkHtml.ts} | 0 src/index.ts | 6 ++-- src/parse/index.ts | 6 ++-- src/parse/state/mustache.ts | 4 +-- src/parse/state/tag.ts | 4 +-- src/utils/{CodeBuilder.js => CodeBuilder.ts} | 0 src/utils/{__test__.js => __test__.ts} | 2 +- ...ateWithScopes.js => annotateWithScopes.ts} | 0 ...lattenReference.js => flattenReference.ts} | 0 .../{getCodeFrame.js => getCodeFrame.ts} | 0 ...{globalWhitelist.js => globalWhitelist.ts} | 0 src/utils/{isReference.js => isReference.ts} | 0 ...oidElementName.js => isVoidElementName.ts} | 0 src/utils/{namespaces.js => namespaces.ts} | 0 src/utils/{patterns.js => patterns.ts} | 0 src/utils/{removeNode.js => removeNode.ts} | 0 .../{reservedNames.js => reservedNames.ts} | 0 src/utils/{toSource.js => toSource.ts} | 0 src/utils/{trim.js => trim.ts} | 2 +- src/validate/html/{index.js => index.ts} | 6 ++-- ...{validateElement.js => validateElement.ts} | 2 +- ...ventHandler.js => validateEventHandler.ts} | 4 +-- .../{validateWindow.js => validateWindow.ts} | 8 ++--- src/validate/{index.js => index.ts} | 6 ++-- src/validate/js/{index.js => index.ts} | 10 +++--- .../{components.js => components.ts} | 4 +-- .../{computed.js => computed.ts} | 4 +-- .../js/propValidators/{data.js => data.ts} | 0 .../propValidators/{events.js => events.ts} | 4 +-- .../propValidators/{helpers.js => helpers.ts} | 4 +-- src/validate/js/propValidators/index.js | 27 -------------- src/validate/js/propValidators/index.ts | 27 ++++++++++++++ .../propValidators/{methods.js => methods.ts} | 8 ++--- .../{namespace.js => namespace.ts} | 4 +-- .../{oncreate.js => oncreate.ts} | 2 +- .../{ondestroy.js => ondestroy.ts} | 2 +- .../{onrender.js => onrender.ts} | 2 +- .../{onteardown.js => onteardown.ts} | 2 +- .../{transitions.js => transitions.ts} | 4 +-- ...ckForAccessors.js => checkForAccessors.ts} | 0 ...omputedKeys.js => checkForComputedKeys.ts} | 0 .../{checkForDupes.js => checkForDupes.ts} | 0 ...sOrArguments.js => usesThisOrArguments.ts} | 2 +- .../utils/{FuzzySet.js => FuzzySet.ts} | 0 .../utils/{fuzzymatch.js => fuzzymatch.ts} | 2 +- src/validate/utils/{list.js => list.ts} | 0 95 files changed, 221 insertions(+), 177 deletions(-) create mode 100644 rename.js rename src/generators/{Generator.js => Generator.ts} (96%) rename src/generators/dom/{Block.js => Block.ts} (99%) rename src/generators/dom/{index.js => index.ts} (96%) rename src/generators/dom/{preprocess.js => preprocess.ts} (98%) create mode 100644 src/generators/dom/shared.ts rename src/generators/dom/{visit.js => visit.ts} (77%) rename src/generators/dom/visitors/Component/{Attribute.js => Attribute.ts} (100%) rename src/generators/dom/visitors/Component/{Binding.js => Binding.ts} (97%) rename src/generators/dom/visitors/Component/{Component.js => Component.ts} (95%) rename src/generators/dom/visitors/Component/{EventHandler.js => EventHandler.ts} (100%) rename src/generators/dom/visitors/Component/{Ref.js => Ref.ts} (100%) rename src/generators/dom/visitors/{EachBlock.js => EachBlock.ts} (99%) rename src/generators/dom/visitors/Element/{Attribute.js => Attribute.ts} (97%) rename src/generators/dom/visitors/Element/{Binding.js => Binding.ts} (98%) rename src/generators/dom/visitors/Element/{Element.js => Element.ts} (91%) rename src/generators/dom/visitors/Element/{EventHandler.js => EventHandler.ts} (99%) rename src/generators/dom/visitors/Element/{Ref.js => Ref.ts} (100%) rename src/generators/dom/visitors/Element/{addTransitions.js => addTransitions.ts} (100%) rename src/generators/dom/visitors/Element/{getStaticAttributeValue.js => getStaticAttributeValue.ts} (100%) rename src/generators/dom/visitors/Element/{lookup.js => lookup.ts} (100%) rename src/generators/dom/visitors/Element/meta/{Window.js => Window.ts} (99%) rename src/generators/dom/visitors/{IfBlock.js => IfBlock.ts} (99%) rename src/generators/dom/visitors/{MustacheTag.js => MustacheTag.ts} (100%) rename src/generators/dom/visitors/{RawMustacheTag.js => RawMustacheTag.ts} (100%) rename src/generators/dom/visitors/{Text.js => Text.ts} (100%) rename src/generators/dom/visitors/{YieldTag.js => YieldTag.ts} (100%) delete mode 100644 src/generators/dom/visitors/index.js create mode 100644 src/generators/dom/visitors/index.ts rename src/generators/dom/visitors/shared/binding/{getSetter.js => getSetter.ts} (100%) rename src/generators/server-side-rendering/{Block.js => Block.ts} (93%) rename src/generators/server-side-rendering/{index.js => index.ts} (96%) rename src/generators/server-side-rendering/{visit.js => visit.ts} (76%) rename src/generators/server-side-rendering/visitors/{Comment.js => Comment.ts} (100%) rename src/generators/server-side-rendering/visitors/{Component.js => Component.ts} (95%) rename src/generators/server-side-rendering/visitors/{EachBlock.js => EachBlock.ts} (96%) rename src/generators/server-side-rendering/visitors/{Element.js => Element.ts} (90%) rename src/generators/server-side-rendering/visitors/{IfBlock.js => IfBlock.ts} (94%) rename src/generators/server-side-rendering/visitors/{MustacheTag.js => MustacheTag.ts} (100%) rename src/generators/server-side-rendering/visitors/{RawMustacheTag.js => RawMustacheTag.ts} (100%) rename src/generators/server-side-rendering/visitors/{Text.js => Text.ts} (100%) rename src/generators/server-side-rendering/visitors/{YieldTag.js => YieldTag.ts} (100%) delete mode 100644 src/generators/server-side-rendering/visitors/index.js create mode 100644 src/generators/server-side-rendering/visitors/index.ts rename src/generators/server-side-rendering/visitors/meta/{Window.js => Window.ts} (100%) rename src/generators/shared/{processCss.js => processCss.ts} (100%) rename src/generators/shared/utils/{getGlobals.js => getGlobals.ts} (100%) rename src/generators/shared/utils/{getIntro.js => getIntro.ts} (98%) rename src/generators/shared/utils/{getOutro.js => getOutro.ts} (94%) rename src/generators/shared/utils/{walkHtml.js => walkHtml.ts} (100%) rename src/utils/{CodeBuilder.js => CodeBuilder.ts} (100%) rename src/utils/{__test__.js => __test__.ts} (98%) rename src/utils/{annotateWithScopes.js => annotateWithScopes.ts} (100%) rename src/utils/{flattenReference.js => flattenReference.ts} (100%) rename src/utils/{getCodeFrame.js => getCodeFrame.ts} (100%) rename src/utils/{globalWhitelist.js => globalWhitelist.ts} (100%) rename src/utils/{isReference.js => isReference.ts} (100%) rename src/utils/{isVoidElementName.js => isVoidElementName.ts} (100%) rename src/utils/{namespaces.js => namespaces.ts} (100%) rename src/utils/{patterns.js => patterns.ts} (100%) rename src/utils/{removeNode.js => removeNode.ts} (100%) rename src/utils/{reservedNames.js => reservedNames.ts} (100%) rename src/utils/{toSource.js => toSource.ts} (100%) rename src/utils/{trim.js => trim.ts} (85%) rename src/validate/html/{index.js => index.ts} (91%) rename src/validate/html/{validateElement.js => validateElement.ts} (98%) rename src/validate/html/{validateEventHandler.js => validateEventHandler.ts} (90%) rename src/validate/html/{validateWindow.js => validateWindow.ts} (85%) rename src/validate/{index.js => index.ts} (92%) rename src/validate/js/{index.js => index.ts} (89%) rename src/validate/js/propValidators/{components.js => components.ts} (92%) rename src/validate/js/propValidators/{computed.js => computed.ts} (95%) rename src/validate/js/propValidators/{data.js => data.ts} (100%) rename src/validate/js/propValidators/{events.js => events.ts} (86%) rename src/validate/js/propValidators/{helpers.js => helpers.ts} (96%) delete mode 100644 src/validate/js/propValidators/index.js create mode 100644 src/validate/js/propValidators/index.ts rename src/validate/js/propValidators/{methods.js => methods.ts} (83%) rename src/validate/js/propValidators/{namespace.js => namespace.ts} (84%) rename src/validate/js/propValidators/{oncreate.js => oncreate.ts} (81%) rename src/validate/js/propValidators/{ondestroy.js => ondestroy.ts} (81%) rename src/validate/js/propValidators/{onrender.js => onrender.ts} (85%) rename src/validate/js/propValidators/{onteardown.js => onteardown.ts} (84%) rename src/validate/js/propValidators/{transitions.js => transitions.ts} (89%) rename src/validate/js/utils/{checkForAccessors.js => checkForAccessors.ts} (100%) rename src/validate/js/utils/{checkForComputedKeys.js => checkForComputedKeys.ts} (100%) rename src/validate/js/utils/{checkForDupes.js => checkForDupes.ts} (100%) rename src/validate/js/utils/{usesThisOrArguments.js => usesThisOrArguments.ts} (89%) rename src/validate/utils/{FuzzySet.js => FuzzySet.ts} (100%) rename src/validate/utils/{fuzzymatch.js => fuzzymatch.ts} (84%) rename src/validate/utils/{list.js => list.ts} (100%) diff --git a/rename.js b/rename.js new file mode 100644 index 000000000000..ad3804e39dab --- /dev/null +++ b/rename.js @@ -0,0 +1,9 @@ +const glob = require( 'glob' ); +const fs = require( 'fs' ); + +glob.sync( 'src/**/*.js' ).forEach( file => { + console.log( file ); + const js = fs.readFileSync( file, 'utf-8' ); + fs.writeFileSync( file.replace( /\.js$/, '.ts' ), js ); + fs.unlinkSync( file ); +}); \ No newline at end of file diff --git a/src/generators/Generator.js b/src/generators/Generator.ts similarity index 96% rename from src/generators/Generator.js rename to src/generators/Generator.ts index 7a316adc85d1..c854806f5b7e 100644 --- a/src/generators/Generator.js +++ b/src/generators/Generator.ts @@ -1,15 +1,15 @@ import MagicString, { Bundle } from 'magic-string'; import { walk } from 'estree-walker'; -import isReference from '../utils/isReference.js'; -import flattenReference from '../utils/flattenReference.js'; -import globalWhitelist from '../utils/globalWhitelist.js'; -import reservedNames from '../utils/reservedNames.js'; -import namespaces from '../utils/namespaces.js'; -import { removeNode, removeObjectKey } from '../utils/removeNode.js'; -import getIntro from './shared/utils/getIntro.js'; -import getOutro from './shared/utils/getOutro.js'; -import processCss from './shared/processCss.js'; -import annotateWithScopes from '../utils/annotateWithScopes.js'; +import isReference from '../utils/isReference.ts'; +import flattenReference from '../utils/flattenReference.ts'; +import globalWhitelist from '../utils/globalWhitelist.ts'; +import reservedNames from '../utils/reservedNames.ts'; +import namespaces from '../utils/namespaces.ts'; +import { removeNode, removeObjectKey } from '../utils/removeNode.ts'; +import getIntro from './shared/utils/getIntro.ts'; +import getOutro from './shared/utils/getOutro.ts'; +import processCss from './shared/processCss.ts'; +import annotateWithScopes from '../utils/annotateWithScopes.ts'; const test = typeof global !== 'undefined' && global.__svelte_test; @@ -39,7 +39,7 @@ export default class Generator { this.usesRefs = false; // allow compiler to deconflict user's `import { get } from 'whatever'` and - // Svelte's builtin `import { get, ... } from 'svelte/shared.js'`; + // Svelte's builtin `import { get, ... } from 'svelte/shared.ts'`; this.importedNames = new Set(); this.aliases = new Map(); this._usedNames = new Set( [ name ] ); diff --git a/src/generators/dom/Block.js b/src/generators/dom/Block.ts similarity index 99% rename from src/generators/dom/Block.js rename to src/generators/dom/Block.ts index 83841b738d6d..a7775bd3553b 100644 --- a/src/generators/dom/Block.js +++ b/src/generators/dom/Block.ts @@ -1,4 +1,4 @@ -import CodeBuilder from '../../utils/CodeBuilder.js'; +import CodeBuilder from '../../utils/CodeBuilder.ts'; import deindent from '../../utils/deindent.js'; export default class Block { diff --git a/src/generators/dom/index.js b/src/generators/dom/index.ts similarity index 96% rename from src/generators/dom/index.js rename to src/generators/dom/index.ts index cb331fd96a7e..e4fa2c6f71a7 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.ts @@ -1,14 +1,14 @@ import MagicString from 'magic-string'; import { parseExpressionAt } from 'acorn'; -import annotateWithScopes from '../../utils/annotateWithScopes.js'; -import isReference from '../../utils/isReference.js'; +import annotateWithScopes from '../../utils/annotateWithScopes.ts'; +import isReference from '../../utils/isReference.ts'; import { walk } from 'estree-walker'; import deindent from '../../utils/deindent.js'; -import CodeBuilder from '../../utils/CodeBuilder.js'; -import visit from './visit.js'; -import shared from './shared.js'; -import Generator from '../Generator.js'; -import preprocess from './preprocess.js'; +import CodeBuilder from '../../utils/CodeBuilder.ts'; +import visit from './visit.ts'; +import shared from './shared.ts'; +import Generator from '../Generator.ts'; +import preprocess from './preprocess.ts'; class DomGenerator extends Generator { constructor ( parsed, source, name, options ) { diff --git a/src/generators/dom/preprocess.js b/src/generators/dom/preprocess.ts similarity index 98% rename from src/generators/dom/preprocess.js rename to src/generators/dom/preprocess.ts index 522a68207483..0de5c2104073 100644 --- a/src/generators/dom/preprocess.js +++ b/src/generators/dom/preprocess.ts @@ -1,5 +1,5 @@ -import Block from './Block.js'; -import { trimStart, trimEnd } from '../../utils/trim.js'; +import Block from './Block.ts'; +import { trimStart, trimEnd } from '../../utils/trim.ts'; import { assign } from '../../shared/index.js'; function isElseIf ( node ) { diff --git a/src/generators/dom/shared.ts b/src/generators/dom/shared.ts new file mode 100644 index 000000000000..a368a0e580d7 --- /dev/null +++ b/src/generators/dom/shared.ts @@ -0,0 +1,35 @@ +// this file is auto-generated, do not edit it +export default { + "appendNode": "function appendNode ( node, target ) {\n\ttarget.appendChild( node );\n}", + "insertNode": "function insertNode ( node, target, anchor ) {\n\ttarget.insertBefore( node, anchor );\n}", + "detachNode": "function detachNode ( node ) {\n\tnode.parentNode.removeChild( node );\n}", + "detachBetween": "function detachBetween ( before, after ) {\n\twhile ( before.nextSibling && before.nextSibling !== after ) {\n\t\tbefore.parentNode.removeChild( before.nextSibling );\n\t}\n}", + "destroyEach": "function destroyEach ( iterations, detach, start ) {\n\tfor ( var i = start; i < iterations.length; i += 1 ) {\n\t\tif ( iterations[i] ) iterations[i].destroy( detach );\n\t}\n}", + "createElement": "function createElement ( name ) {\n\treturn document.createElement( name );\n}", + "createSvgElement": "function createSvgElement ( name ) {\n\treturn document.createElementNS( 'http://www.w3.org/2000/svg', name );\n}", + "createText": "function createText ( data ) {\n\treturn document.createTextNode( data );\n}", + "createComment": "function createComment () {\n\treturn document.createComment( '' );\n}", + "addEventListener": "function addEventListener ( node, event, handler ) {\n\tnode.addEventListener( event, handler, false );\n}", + "removeEventListener": "function removeEventListener ( node, event, handler ) {\n\tnode.removeEventListener( event, handler, false );\n}", + "setAttribute": "function setAttribute ( node, attribute, value ) {\n\tnode.setAttribute( attribute, value );\n}", + "setXlinkAttribute": "function setXlinkAttribute ( node, attribute, value ) {\n\tnode.setAttributeNS( 'http://www.w3.org/1999/xlink', attribute, value );\n}", + "getBindingGroupValue": "function getBindingGroupValue ( group ) {\n\tvar value = [];\n\tfor ( var i = 0; i < group.length; i += 1 ) {\n\t\tif ( group[i].checked ) value.push( group[i].__value );\n\t}\n\treturn value;\n}", + "differs": "function differs ( a, b ) {\n\treturn ( a !== b ) || ( a && ( typeof a === 'object' ) || ( typeof a === 'function' ) );\n}", + "dispatchObservers": "function dispatchObservers ( component, group, newState, oldState ) {\n\tfor ( var key in group ) {\n\t\tif ( !( key in newState ) ) continue;\n\n\t\tvar newValue = newState[ key ];\n\t\tvar oldValue = oldState[ key ];\n\n\t\tif ( differs( newValue, oldValue ) ) {\n\t\t\tvar callbacks = group[ key ];\n\t\t\tif ( !callbacks ) continue;\n\n\t\t\tfor ( var i = 0; i < callbacks.length; i += 1 ) {\n\t\t\t\tvar callback = callbacks[i];\n\t\t\t\tif ( callback.__calling ) continue;\n\n\t\t\t\tcallback.__calling = true;\n\t\t\t\tcallback.call( component, newValue, oldValue );\n\t\t\t\tcallback.__calling = false;\n\t\t\t}\n\t\t}\n\t}\n}", + "get": "function get ( key ) {\n\treturn key ? this._state[ key ] : this._state;\n}", + "fire": "function fire ( eventName, data ) {\n\tvar handlers = eventName in this._handlers && this._handlers[ eventName ].slice();\n\tif ( !handlers ) return;\n\n\tfor ( var i = 0; i < handlers.length; i += 1 ) {\n\t\thandlers[i].call( this, data );\n\t}\n}", + "observe": "function observe ( key, callback, options ) {\n\tvar group = ( options && options.defer ) ? this._observers.post : this._observers.pre;\n\n\t( group[ key ] || ( group[ key ] = [] ) ).push( callback );\n\n\tif ( !options || options.init !== false ) {\n\t\tcallback.__calling = true;\n\t\tcallback.call( this, this._state[ key ] );\n\t\tcallback.__calling = false;\n\t}\n\n\treturn {\n\t\tcancel: function () {\n\t\t\tvar index = group[ key ].indexOf( callback );\n\t\t\tif ( ~index ) group[ key ].splice( index, 1 );\n\t\t}\n\t};\n}", + "observeDev": "function observeDev ( key, callback, options ) {\n\tvar c = ( key = '' + key ).search( /[^\\w]/ );\n\tif ( c > -1 ) {\n\t\tvar message = \"The first argument to component.observe(...) must be the name of a top-level property\";\n\t\tif ( c > 0 ) message += \", i.e. '\" + key.slice( 0, c ) + \"' rather than '\" + key + \"'\";\n\n\t\tthrow new Error( message );\n\t}\n\n\treturn observe.call( this, key, callback, options );\n}", + "on": "function on ( eventName, handler ) {\n\tif ( eventName === 'teardown' ) return this.on( 'destroy', handler );\n\n\tvar handlers = this._handlers[ eventName ] || ( this._handlers[ eventName ] = [] );\n\thandlers.push( handler );\n\n\treturn {\n\t\tcancel: function () {\n\t\t\tvar index = handlers.indexOf( handler );\n\t\t\tif ( ~index ) handlers.splice( index, 1 );\n\t\t}\n\t};\n}", + "onDev": "function onDev ( eventName, handler ) {\n\tif ( eventName === 'teardown' ) {\n\t\tconsole.warn( \"Use component.on('destroy', ...) instead of component.on('teardown', ...) which has been deprecated and will be unsupported in Svelte 2\" );\n\t\treturn this.on( 'destroy', handler );\n\t}\n\n\treturn on.call( this, eventName, handler );\n}", + "set": "function set ( newState ) {\n\tthis._set( assign( {}, newState ) );\n\tthis._root._flush();\n}", + "_flush": "function _flush () {\n\tif ( !this._renderHooks ) return;\n\n\twhile ( this._renderHooks.length ) {\n\t\tthis._renderHooks.pop()();\n\t}\n}", + "proto": "{\n\tget: get,\n\tfire: fire,\n\tobserve: observe,\n\ton: on,\n\tset: set,\n\t_flush: _flush\n}", + "protoDev": "{\n\tget: get,\n\tfire: fire,\n\tobserve: observeDev,\n\ton: onDev,\n\tset: set,\n\t_flush: _flush\n}", + "linear": "function linear ( t ) {\n\treturn t;\n}", + "generateKeyframes": "function generateKeyframes ( a, b, delta, duration, ease, fn, node, style ) {\n\tvar id = '__svelte' + ~~( Math.random() * 1e9 ); // TODO make this more robust\n\tvar keyframes = '@keyframes ' + id + '{\\n';\n\n\tfor ( var p = 0; p <= 1; p += 16.666 / duration ) {\n\t\tvar t = a + delta * ease( p );\n\t\tkeyframes += ( p * 100 ) + '%{' + fn( t ) + '}\\n';\n\t}\n\n\tkeyframes += '100% {' + fn( b ) + '}\\n}';\n\tstyle.textContent += keyframes;\n\n\tdocument.head.appendChild( style );\n\n\tnode.style.animation = node.style.animation.split( ',' )\n\t\t.filter( function ( anim ) {\n\t\t\t// when introing, discard old animations if there are any\n\t\t\treturn anim && ( delta < 0 || !/__svelte/.test( anim ) );\n\t\t})\n\t\t.concat( id + ' ' + duration + 'ms linear 1 forwards' )\n\t\t.join( ', ' );\n}", + "wrapTransition": "function wrapTransition ( node, fn, params, intro, outgroup ) {\n\tvar obj = fn( node, params );\n\tvar duration = obj.duration || 300;\n\tvar ease = obj.easing || linear;\n\n\t// TODO share