Skip to content

Commit

Permalink
merge master -> zxbodya-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed May 26, 2019
2 parents 0891495 + 33f827c commit 285ed4f
Show file tree
Hide file tree
Showing 42 changed files with 247 additions and 186 deletions.
17 changes: 9 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
node_modules
*.map
/src/compile/internal-exports.ts
/compiler.js
/index.js
/internal.*
/store.*
/easing.js
/motion.*
/transition.js
/animate.js
/compiler.*js
/index.*js
/internal.*js
/store.*js
/easing.*js
/motion.*js
/transition.*js
/animate.*js
/scratch/
/coverage/
/coverage.lcov/
Expand All @@ -21,6 +21,7 @@ node_modules
/test/sourcemaps/samples/*/output.css.map
/yarn-error.log
_actual*.*
/dist

/site/cypress/screenshots/
/site/__sapper__/
Expand Down
1 change: 1 addition & 0 deletions animate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/animate';
1 change: 1 addition & 0 deletions compiler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/compiler';
1 change: 1 addition & 0 deletions easing.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/easing';
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/index';
10 changes: 0 additions & 10 deletions index.mjs

This file was deleted.

1 change: 1 addition & 0 deletions internal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/internal';
1 change: 1 addition & 0 deletions motion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/motion';
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"prepare": "npm run build && npm run tsd",
"dev": "rollup -cw",
"pretest": "npm run build",
"posttest": "agadoo src/internal/index.js",
"posttest": "agadoo internal.mjs",
"prepublishOnly": "export PUBLISH=true && npm run lint && npm test",
"tsd": "tsc -d src/store.ts --outDir .",
"typecheck": "tsc --noEmit"
"tsd": "tsc -p . --emitDeclarationOnly",
"typecheck": "tsc -p . --noEmit"
},
"repository": {
"type": "git",
Expand Down
76 changes: 32 additions & 44 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ import pkg from './package.json';

const is_publish = !!process.env.PUBLISH;

const tsPlugin = is_publish
? typescript({
include: 'src/**',
typescript: require('typescript')
})
: sucrase({
transforms: ['typescript']
});

export default [
/* internal.[m]js */
{
input: `src/internal/index.js`,
input: `src/internal/index.ts`,
output: [
{
file: `internal.mjs`,
Expand All @@ -26,19 +35,22 @@ export default [
}
],
external: id => id.startsWith('svelte/'),
plugins: [{
generateBundle(options, bundle) {
const mod = bundle['internal.mjs'];
if (mod) {
fs.writeFileSync('src/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`);

plugins: [
tsPlugin,
{
generateBundle(options, bundle) {
const mod = bundle['internal.mjs'];
if (mod) {
fs.writeFileSync('src/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`);
}
}
}
}]
}]
},

/* compiler.js */
{
input: 'src/index.ts',
input: 'src/compiler.ts',
plugins: [
replace({
__VERSION__: pkg.version
Expand All @@ -48,15 +60,7 @@ export default [
include: ['node_modules/**']
}),
json(),
is_publish
? typescript({
include: 'src/**',
exclude: 'src/internal/**',
typescript: require('typescript')
})
: sucrase({
transforms: ['typescript']
})
tsPlugin
],
output: {
file: 'compiler.js',
Expand All @@ -71,7 +75,7 @@ export default [

/* motion.mjs */
{
input: `src/motion/index.js`,
input: `src/motion/index.ts`,
output: [
{
file: `motion.mjs`,
Expand All @@ -84,46 +88,30 @@ export default [
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
}
],
plugins: [
tsPlugin
],
external: id => id.startsWith('svelte/')
},

/* store.mjs */
{
input: `src/store.ts`,
// everything else
...['index', 'easing', 'transition', 'animate', 'store'].map(name => ({
input: `src/${name}.ts`,
output: [
{
file: `store.mjs`,
file: `${name}.mjs`,
format: 'esm',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
},
{
file: `store.js`,
file: `${name}.js`,
format: 'cjs',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
}
],
plugins: [
is_publish
? typescript({
include: 'src/**',
exclude: 'src/internal/**',
typescript: require('typescript')
})
: sucrase({
transforms: ['typescript']
})
tsPlugin
],
external: id => id.startsWith('svelte/')
},

// everything else
...['index', 'easing', 'transition', 'animate'].map(name => ({
input: `${name}.mjs`,
output: {
file: `${name}.js`,
format: 'cjs',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
},
external: id => id !== `${name}.mjs`
}))
];
6 changes: 3 additions & 3 deletions animate.mjs → src/animate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cubicOut } from './easing';
import { is_function } from './internal';
import { cubicOut } from 'svelte/easing';
import { is_function } from 'svelte/internal';

export function flip(node, animation, params) {
const style = getComputedStyle(node);
Expand All @@ -22,4 +22,4 @@ export function flip(node, animation, params) {
easing,
css: (t, u) => `transform: ${transform} translate(${u * dx}px, ${u * dy}px);`
};
}
}
2 changes: 1 addition & 1 deletion src/compile/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assign } from '../internal';
import { assign } from '../internal/index';
import Stats from '../Stats';
import parse from '../parse/index';
import render_dom from './render-dom/index';
Expand Down
2 changes: 1 addition & 1 deletion src/compile/render-dom/wrappers/RawMustacheTag.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Renderer from '../Renderer';
import Block from '../Block';
import Tag from './shared/Tag';
import Wrapper from './shared/wrapper';
import Wrapper from './shared/Wrapper';
import deindent from '../../utils/deindent';
import MustacheTag from '../../nodes/MustacheTag';
import RawMustacheTag from '../../nodes/RawMustacheTag';
Expand Down
6 changes: 6 additions & 0 deletions src/compiler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { default as compile } from './compile/index';
export { default as parse } from './parse/index';
export { default as preprocess } from './preprocess/index';
export { walk } from 'estree-walker';

export const VERSION = '__VERSION__';
2 changes: 1 addition & 1 deletion easing.mjs → src/easing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Adapted from https://github.com/mattdesl
Distributed under MIT License https://github.com/mattdesl/eases/blob/master/LICENSE.md
*/

export { identity as linear } from './internal';
export { identity as linear } from 'svelte/internal';

export function backInOut(t) {
const s = 1.70158 * 1.525;
Expand Down
16 changes: 10 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export { default as compile } from './compile/index';
export { default as parse } from './parse/index';
export { default as preprocess } from './preprocess/index';
export { walk } from 'estree-walker';

export const VERSION = '__VERSION__';
export {
onMount,
onDestroy,
beforeUpdate,
afterUpdate,
setContext,
getContext,
tick,
createEventDispatcher
} from 'svelte/internal';
35 changes: 28 additions & 7 deletions src/internal/Component.js → src/internal/Component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler.js';
import { current_component, set_current_component } from './lifecycle.js';
import { blank_object, is_function, run, run_all, noop } from './utils.js';
import { children } from './dom.js';
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
import { current_component, set_current_component } from './lifecycle';
import { blank_object, is_function, run, run_all, noop } from './utils';
import { children } from './dom';

interface T$$ {
dirty: null;
ctx: null|any;
bound: any;
update: () => void;
callbacks: any;
after_render: any[];
props: any;
fragment: null|any;
not_equal: any;
before_render: any[];
context: Map<any, any>;
on_mount: any[];
on_destroy: any[]
}

export function bind(component, name, callback) {
if (component.$$.props.indexOf(name) === -1) return;
Expand Down Expand Up @@ -59,7 +75,7 @@ export function init(component, options, instance, create_fragment, not_equal, p

const props = options.props || {};

const $$ = component.$$ = {
const $$: T$$ = component.$$ = {
fragment: null,
ctx: null,

Expand Down Expand Up @@ -99,9 +115,9 @@ export function init(component, options, instance, create_fragment, not_equal, p

if (options.target) {
if (options.hydrate) {
$$.fragment.l(children(options.target));
$$.fragment!.l(children(options.target));
} else {
$$.fragment.c();
$$.fragment!.c();
}

if (options.intro && component.$$.fragment.i) component.$$.fragment.i();
Expand All @@ -115,13 +131,16 @@ export function init(component, options, instance, create_fragment, not_equal, p
export let SvelteElement;
if (typeof HTMLElement !== 'undefined') {
SvelteElement = class extends HTMLElement {
$$: T$$;
constructor() {
super();
this.attachShadow({ mode: 'open' });
}

connectedCallback() {
// @ts-ignore todo: improve typings
for (const key in this.$$.slotted) {
// @ts-ignore todo: improve typings
this.appendChild(this.$$.slotted[key]);
}
}
Expand Down Expand Up @@ -153,6 +172,8 @@ if (typeof HTMLElement !== 'undefined') {
}

export class SvelteComponent {
$$: T$$;

$destroy() {
destroy(this, true);
this.$destroy = noop;
Expand Down
8 changes: 4 additions & 4 deletions src/internal/animations.js → src/internal/animations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { identity as linear, noop, now } from './utils.js';
import { loop } from './loop.js';
import { create_rule, delete_rule } from './style_manager.js';
import { identity as linear, noop, now } from './utils';
import { loop } from './loop';
import { create_rule, delete_rule } from './style_manager';

export function create_animation(node, from, fn, params) {
if (!from) return noop;
Expand Down Expand Up @@ -90,4 +90,4 @@ export function fix_position(node) {
node.style.transform = `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`;
}
}
}
}
10 changes: 5 additions & 5 deletions src/internal/await-block.js → src/internal/await-block.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { assign, is_promise } from './utils.js';
import { check_outros, group_outros, on_outro } from './transitions.js';
import { flush } from '../internal/scheduler.js';
import { assign, is_promise } from './utils';
import { check_outros, group_outros, on_outro } from './transitions';
import { flush } from '../internal/scheduler';

export function handle_promise(promise, info) {
const token = info.token = {};

function update(type, index, key, value) {
function update(type, index, key?, value?) {
if (info.token !== token) return;

info.resolved = key && { [key]: value };
Expand Down Expand Up @@ -61,4 +61,4 @@ export function handle_promise(promise, info) {

info.resolved = { [info.value]: promise };
}
}
}
Loading

0 comments on commit 285ed4f

Please sign in to comment.