various tweaks

pull/1839/head
Rich Harris 7 years ago
parent 578a2bca08
commit ed23d7acb3

@ -204,7 +204,6 @@ export default class Component {
}); });
const importedHelpers = Array.from(helpers) const importedHelpers = Array.from(helpers)
.concat(options.dev ? 'SvelteComponentDev' : 'SvelteComponent')
.sort() .sort()
.map(name => { .map(name => {
const alias = this.alias(name); const alias = this.alias(name);

@ -116,9 +116,9 @@ class Declaration {
if (!this.node.property) return; // @apply, and possibly other weird cases? if (!this.node.property) return; // @apply, and possibly other weird cases?
const c = this.node.start + this.node.property.length; const c = this.node.start + this.node.property.length;
const first = this.node.value.children ? const first = this.node.value.children
this.node.value.children[0] : ? this.node.value.children[0]
this.node.value; : this.node.value;
let start = first.start; let start = first.start;
while (/\s/.test(code.original[start])) start += 1; while (/\s/.test(code.original[start])) start += 1;

@ -246,7 +246,7 @@ export default class Block {
} }
if (this.builders.create.isEmpty() && this.builders.hydrate.isEmpty()) { if (this.builders.create.isEmpty() && this.builders.hydrate.isEmpty()) {
properties.addBlock(`c: @noop,`); properties.addLine(`c: @noop,`);
} else { } else {
const hydrate = !this.builders.hydrate.isEmpty() && ( const hydrate = !this.builders.hydrate.isEmpty() && (
this.renderer.options.hydratable this.renderer.options.hydratable
@ -264,7 +264,7 @@ export default class Block {
if (this.renderer.options.hydratable || !this.builders.claim.isEmpty()) { if (this.renderer.options.hydratable || !this.builders.claim.isEmpty()) {
if (this.builders.claim.isEmpty() && this.builders.hydrate.isEmpty()) { if (this.builders.claim.isEmpty() && this.builders.hydrate.isEmpty()) {
properties.addBlock(`l: @noop,`); properties.addLine(`l: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'l: function claim' : 'l'}(nodes) { ${dev ? 'l: function claim' : 'l'}(nodes) {
@ -284,7 +284,7 @@ export default class Block {
} }
if (this.builders.mount.isEmpty()) { if (this.builders.mount.isEmpty()) {
properties.addBlock(`m: @noop,`); properties.addLine(`m: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'm: function mount' : 'm'}(#target, anchor) { ${dev ? 'm: function mount' : 'm'}(#target, anchor) {
@ -295,7 +295,7 @@ export default class Block {
if (this.hasUpdateMethod || this.maintainContext) { if (this.hasUpdateMethod || this.maintainContext) {
if (this.builders.update.isEmpty() && !this.maintainContext) { if (this.builders.update.isEmpty() && !this.maintainContext) {
properties.addBlock(`p: @noop,`); properties.addLine(`p: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'p: function update' : 'p'}(changed, ${this.maintainContext ? 'new_ctx' : 'ctx'}) { ${dev ? 'p: function update' : 'p'}(changed, ${this.maintainContext ? 'new_ctx' : 'ctx'}) {
@ -324,7 +324,7 @@ export default class Block {
if (this.hasIntroMethod || this.hasOutroMethod) { if (this.hasIntroMethod || this.hasOutroMethod) {
if (this.builders.mount.isEmpty()) { if (this.builders.mount.isEmpty()) {
properties.addBlock(`i: @noop,`); properties.addLine(`i: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'i: function intro' : 'i'}(#target, anchor) { ${dev ? 'i: function intro' : 'i'}(#target, anchor) {
@ -336,7 +336,7 @@ export default class Block {
} }
if (this.builders.outro.isEmpty()) { if (this.builders.outro.isEmpty()) {
properties.addBlock(`o: @run,`); properties.addLine(`o: @run,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'o: function outro' : 'o'}(#outrocallback) { ${dev ? 'o: function outro' : 'o'}(#outrocallback) {
@ -351,7 +351,7 @@ export default class Block {
} }
if (this.builders.destroy.isEmpty()) { if (this.builders.destroy.isEmpty()) {
properties.addBlock(`d: @noop`); properties.addLine(`d: @noop`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'd: function destroy' : 'd'}(detach) { ${dev ? 'd: function destroy' : 'd'}(detach) {

@ -53,8 +53,6 @@ export default function dom(
const refs = Array.from(component.refs); const refs = Array.from(component.refs);
const superclass = component.alias(options.dev ? 'SvelteComponentDev' : 'SvelteComponent');
if (options.dev && !options.hydratable) { if (options.dev && !options.hydratable) {
block.builders.claim.addLine( block.builders.claim.addLine(
'throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");' 'throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");'
@ -182,7 +180,7 @@ export default function dom(
${component.fully_hoisted.length > 0 && component.fully_hoisted.join('\n\n')} ${component.fully_hoisted.length > 0 && component.fully_hoisted.join('\n\n')}
`); `);
let has_definition = ( const has_definition = (
component.javascript || component.javascript ||
component.props.length > 0 || component.props.length > 0 ||
component.partly_hoisted.length > 0 || component.partly_hoisted.length > 0 ||
@ -246,8 +244,10 @@ export default function dom(
customElements.define("${component.tag}", ${name}); customElements.define("${component.tag}", ${name});
`); `);
} else { } else {
const superclass = options.dev ? 'SvelteComponentDev' : 'SvelteComponent';
builder.addBlock(deindent` builder.addBlock(deindent`
class ${name} extends ${superclass} { class ${name} extends @${superclass} {
constructor(options) { constructor(options) {
super(${options.dev && `options`}); super(${options.dev && `options`});
${should_add_css && `if (!document.getElementById("${component.stylesheet.id}-style")) @add_css();`} ${should_add_css && `if (!document.getElementById("${component.stylesheet.id}-style")) @add_css();`}

@ -23,11 +23,12 @@ export default function ssr(
// TODO concatenate CSS maps // TODO concatenate CSS maps
return (deindent` return (deindent`
${component.javascript && deindent`
function #define($$props) { function #define($$props) {
${component.javascript} ${component.javascript}
return { ${component.declarations.join(', ')} }; return { ${component.declarations.join(', ')} };
} }`}
var ${name} = {}; var ${name} = {};

@ -373,16 +373,18 @@ function readAttribute(parser: Parser, uniqueNames: Set<string>) {
uniqueNames.add(name); uniqueNames.add(name);
let end = parser.index;
parser.allowWhitespace(); parser.allowWhitespace();
const colon_index = name.indexOf(':'); const colon_index = name.indexOf(':');
const type = colon_index !== 1 && get_directive_type(name.slice(0, colon_index)); const type = colon_index !== 1 && get_directive_type(name.slice(0, colon_index));
const value = parser.eat('=') let value: any[] | true = true;
? readAttributeValue(parser) if (parser.eat('=')) {
: true; value = readAttributeValue(parser);
end = parser.index;
const end = parser.index; }
if (type) { if (type) {
const directive_name = name.slice(colon_index + 1); const directive_name = name.slice(colon_index + 1);

@ -3,7 +3,7 @@ import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { loadConfig, svelte } from "../helpers.js"; import { loadConfig, svelte } from "../helpers.js";
describe("js", () => { describe.only("js", () => {
fs.readdirSync("test/js/samples").forEach(dir => { fs.readdirSync("test/js/samples").forEach(dir => {
if (dir[0] === ".") return; if (dir[0] === ".") return;

@ -19,7 +19,7 @@ function create_fragment(component, ctx) {
}; };
} }
function define($$self, $$props, $$make_dirty) { function define($$self, $$props) {
let { x } = $$props; let { x } = $$props;
function a() { function a() {

@ -143,7 +143,6 @@ function create_fragment(component, ctx) {
function define($$self, $$props) { function define($$self, $$props) {
let { things, foo } = $$props; let { things, foo } = $$props;
// TODO only what's needed by the template
$$self.$$.get = () => ({ things, foo }); $$self.$$.get = () => ({ things, foo });
$$self.$$.set = $$props => { $$self.$$.set = $$props => {

@ -97,7 +97,6 @@ function create_fragment(component, ctx) {
function define($$self, $$props) { function define($$self, $$props) {
let { foo } = $$props; let { foo } = $$props;
// TODO only what's needed by the template
$$self.$$.get = () => ({ foo }); $$self.$$.get = () => ({ foo });
$$self.$$.set = $$props => { $$self.$$.set = $$props => {

@ -29,8 +29,8 @@ function create_fragment(component, ctx) {
}, },
p(changed, ctx) { p(changed, ctx) {
if (!audio_updating && !isNaN(ctx.currentTime ) && changed.currentTime) audio.currentTime = ctx.currentTime ; if (!audio_updating && !isNaN(ctx.currentTime) && changed.currentTime) audio.currentTime = ctx.currentTime;
if (!audio_updating && audio_is_paused !== (audio_is_paused = ctx.paused ) && changed.paused) audio[audio_is_paused ? "pause" : "play"](); if (!audio_updating && audio_is_paused !== (audio_is_paused = ctx.paused) && changed.paused) audio[audio_is_paused ? "pause" : "play"]();
if (!audio_updating && !isNaN(ctx.volume) && changed.volume) audio.volume = ctx.volume; if (!audio_updating && !isNaN(ctx.volume) && changed.volume) audio.volume = ctx.volume;
}, },
@ -58,7 +58,7 @@ function create_fragment(component, ctx) {
}; };
} }
function define($$self, $$make_dirty) { function define($$self, $$props, $$make_dirty) {
// TODO some of these are read-only... // TODO some of these are read-only...
let { buffered, seekable, played, currentTime, duration, paused, volume } = $$props; let { buffered, seekable, played, currentTime, duration, paused, volume } = $$props;

@ -1,4 +1,5 @@
/* generated by Svelte vX.Y.Z-alpha1 */ /* generated by Svelte vX.Y.Z-alpha1 */
var SvelteComponent = {}; var SvelteComponent = {};
SvelteComponent.render = function(props = {}, options = {}) { SvelteComponent.render = function(props = {}, options = {}) {
@ -37,4 +38,5 @@ SvelteComponent.css = {
}; };
var warned = false; var warned = false;
export default SvelteComponent; export default SvelteComponent;

@ -8,7 +8,6 @@ function create_fragment(component, ctx) {
return { return {
c: noop, c: noop,
m: noop, m: noop,
p(changed, ctx) { p(changed, ctx) {
@ -18,9 +17,7 @@ function create_fragment(component, ctx) {
}, },
i: noop, i: noop,
o: run, o: run,
d: noop d: noop
}; };
} }

@ -21,7 +21,7 @@ function tryToReadFile(file) {
const sveltePath = process.cwd(); const sveltePath = process.cwd();
describe.only("ssr", () => { describe("ssr", () => {
before(() => { before(() => {
require("../../register")({ require("../../register")({
extensions: ['.svelte', '.html'], extensions: ['.svelte', '.html'],

Loading…
Cancel
Save