Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection of small fixes #2994

Merged
merged 7 commits into from
Jun 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .flowconfig

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
node_modules
*.map
/src/compiler/compile/internal-exports.ts
/compiler.d.ts
/compiler.*js
/index.*js
/internal
Expand Down
1 change: 0 additions & 1 deletion compiler.d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"engines": {
"node": ">= 8"
},
"types": "types/runtime",
"types": "types/runtime/index.d.ts",
"scripts": {
"test": "mocha --opts mocha.opts",
"test:unit": "mocha --require sucrase/register --recursive ./**/__test__.ts",
Expand All @@ -35,10 +35,8 @@
"dev": "rollup -cw",
"pretest": "npm run build",
"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",
"prepublishOnly": "PUBLISH=true npm test",
"tsd": "tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly",
"lint": "eslint \"{src,test}/**/*.{ts,js}\""
},
"repository": {
Expand All @@ -59,7 +57,7 @@
"homepage": "https://github.com/sveltejs/svelte#README",
"devDependencies": {
"@types/mocha": "^5.2.0",
"@types/node": "^10.5.5",
"@types/node": "=8",
Conduitry marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"acorn": "^6.1.1",
Expand Down
22 changes: 17 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const ts_plugin = is_publish

const external = id => id.startsWith('svelte/');

fs.writeFileSync(`./compiler.d.ts`, `export * from './types/compiler/index';`);
Conduitry marked this conversation as resolved.
Show resolved Hide resolved

export default [
/* runtime */
{
Expand Down Expand Up @@ -59,12 +61,22 @@ export default [
external,
plugins: [
ts_plugin,
dir === 'internal' && {
generateBundle(options, bundle) {
const mod = bundle['index.mjs'];
if (mod) {
fs.writeFileSync('src/compiler/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`);
{
writeBundle(bundle) {
if (dir === 'internal') {
const mod = bundle['index.mjs'];
if (mod) {
fs.writeFileSync('src/compiler/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`);
}
}

fs.writeFileSync(`${dir}/package.json`, JSON.stringify({
main: './index',
module: './index.mjs',
types: './index.d.ts'
}, null, ' '));

fs.writeFileSync(`${dir}/index.d.ts`, `export * from '../types/runtime/${dir}/index';`);
}
}
]
Expand Down
12 changes: 0 additions & 12 deletions scripts/create-stubs.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/compiler/compile/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ export default class Element extends Node {
} else if (
name === 'text' ||
name === 'html'
){
) {
const contenteditable = this.attributes.find(
(attribute: Attribute) => attribute.name === 'contenteditable'
);
Expand All @@ -626,7 +626,7 @@ export default class Element extends Node {
message: `'contenteditable' attribute cannot be dynamic if element uses two-way binding`
});
}
} else if (name !== 'this') {
} else if (name !== 'this') {
component.error(binding, {
code: `invalid-binding`,
message: `'${binding.name}' is not a valid binding`
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/compile/render-ssr/handlers/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
if (name === 'group') {
// TODO server-render group bindings
} else if (contenteditable && (name === 'text' || name === 'html')) {
const snippet = snip(expression)
const snippet = snip(expression);
if (name == 'text') {
node_contents = '${@escape(' + snippet + ')}'
node_contents = '${@escape(' + snippet + ')}';
} else {
// Do not escape HTML content
node_contents = '${' + snippet + '}'
node_contents = '${' + snippet + '}';
}
} else if (binding.name === 'value' && node.name === 'textarea') {
const snippet = snip(expression);
Expand Down
11 changes: 11 additions & 0 deletions src/compiler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"include": ["."],

"compilerOptions": {
"lib": ["es2017", "webworker"]

// TODO: remove mocha types from the whole project
// "types": ["node", "estree"]
}
}
3 changes: 2 additions & 1 deletion src/runtime/internal/animations.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
16 changes: 16 additions & 0 deletions src/runtime/internal/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const is_client = typeof window !== 'undefined';

export let now: () => number = is_client
? () => window.performance.now()
: () => Date.now();

export let raf = cb => requestAnimationFrame(cb);

// used internally for testing
export function set_now(fn) {
now = fn;
}

export function set_raf(fn) {
raf = fn;
}
1 change: 1 addition & 0 deletions src/runtime/internal/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/internal/loop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { now, raf } from './utils';
import { now, raf } from './environment';

export interface Task { abort(): void; promise: Promise<void> }

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/internal/style_manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { element } from './dom';
import { raf } from './utils';
import { raf } from './environment';

let stylesheet;
let active = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/internal/transitions.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
17 changes: 0 additions & 17 deletions src/runtime/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = cb => requestAnimationFrame(cb);

// used internally for testing
export function set_now(fn) {
now = fn;
}

export function set_raf(fn) {
raf = fn;
}
15 changes: 15 additions & 0 deletions src/runtime/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"include": ["."],

"compilerOptions": {
"lib": ["es2015", "dom", "dom.iterable"],
"target": "es2015",
"types": [],

"baseUrl": ".",
"paths": {
"svelte/*": ["*"]
}
}
}
6 changes: 3 additions & 3 deletions test/runtime/samples/contenteditable-html/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export default {

el.innerHTML = 'every<span>body</span>';

// No updates to data yet
// No updates to data yet
assert.htmlEqual(target.innerHTML, `
<editor>every<span>body</span></editor>
<p>hello <b>world</b></p>
`);

// Handle user input
const event = new window.Event('input');
// Handle user input
const event = new window.Event('input');
await el.dispatchEvent(event);
assert.htmlEqual(target.innerHTML, `
<editor>every<span>body</span></editor>
Expand Down
2 changes: 0 additions & 2 deletions test/server-side-rendering/samples/styles-nested/_actual.css

This file was deleted.

1 change: 0 additions & 1 deletion test/server-side-rendering/samples/styles/_actual.css

This file was deleted.

10 changes: 10 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"include": ["."],

"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true
}
}
49 changes: 23 additions & 26 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
{
"include": [],

"compilerOptions": {
"target": "es2015",
"module": "es6",
"rootDir": "src",

// target node v8+ (https://node.green/)
// the only missing feature is Array.prototype.values
"lib": ["es2017"],
"target": "es2017",

"declaration": true,
"declarationDir": "types",
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,

"noEmitOnError": true,
"lib": [
"es5",
"es6",
"dom",
"es2015"
],
"importHelpers": true,
"noErrorTruncation": true,

// rollup takes care of these
"module": "esnext",
"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/**/*"
]
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,

// TODO: error all the things
//"strict": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true
}
}