diff --git a/rename.js b/rename.js new file mode 100644 index 0000000000..ad3804e39d --- /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 7a316adc85..c854806f5b 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 83841b738d..a7775bd355 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 cb331fd96a..e4fa2c6f71 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 522a682074..0de5c21040 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 0000000000..a368a0e580 --- /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