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)
.concat(options.dev ? 'SvelteComponentDev' : 'SvelteComponent')
.sort()
.map(name => {
const alias = this.alias(name);

@ -116,9 +116,9 @@ class Declaration {
if (!this.node.property) return; // @apply, and possibly other weird cases?
const c = this.node.start + this.node.property.length;
const first = this.node.value.children ?
this.node.value.children[0] :
this.node.value;
const first = this.node.value.children
? this.node.value.children[0]
: this.node.value;
let start = first.start;
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()) {
properties.addBlock(`c: @noop,`);
properties.addLine(`c: @noop,`);
} else {
const hydrate = !this.builders.hydrate.isEmpty() && (
this.renderer.options.hydratable
@ -264,7 +264,7 @@ export default class Block {
if (this.renderer.options.hydratable || !this.builders.claim.isEmpty()) {
if (this.builders.claim.isEmpty() && this.builders.hydrate.isEmpty()) {
properties.addBlock(`l: @noop,`);
properties.addLine(`l: @noop,`);
} else {
properties.addBlock(deindent`
${dev ? 'l: function claim' : 'l'}(nodes) {
@ -284,7 +284,7 @@ export default class Block {
}
if (this.builders.mount.isEmpty()) {
properties.addBlock(`m: @noop,`);
properties.addLine(`m: @noop,`);
} else {
properties.addBlock(deindent`
${dev ? 'm: function mount' : 'm'}(#target, anchor) {
@ -295,7 +295,7 @@ export default class Block {
if (this.hasUpdateMethod || this.maintainContext) {
if (this.builders.update.isEmpty() && !this.maintainContext) {
properties.addBlock(`p: @noop,`);
properties.addLine(`p: @noop,`);
} else {
properties.addBlock(deindent`
${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.builders.mount.isEmpty()) {
properties.addBlock(`i: @noop,`);
properties.addLine(`i: @noop,`);
} else {
properties.addBlock(deindent`
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
@ -336,7 +336,7 @@ export default class Block {
}
if (this.builders.outro.isEmpty()) {
properties.addBlock(`o: @run,`);
properties.addLine(`o: @run,`);
} else {
properties.addBlock(deindent`
${dev ? 'o: function outro' : 'o'}(#outrocallback) {
@ -351,7 +351,7 @@ export default class Block {
}
if (this.builders.destroy.isEmpty()) {
properties.addBlock(`d: @noop`);
properties.addLine(`d: @noop`);
} else {
properties.addBlock(deindent`
${dev ? 'd: function destroy' : 'd'}(detach) {

@ -53,8 +53,6 @@ export default function dom(
const refs = Array.from(component.refs);
const superclass = component.alias(options.dev ? 'SvelteComponentDev' : 'SvelteComponent');
if (options.dev && !options.hydratable) {
block.builders.claim.addLine(
'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')}
`);
let has_definition = (
const has_definition = (
component.javascript ||
component.props.length > 0 ||
component.partly_hoisted.length > 0 ||
@ -246,8 +244,10 @@ export default function dom(
customElements.define("${component.tag}", ${name});
`);
} else {
const superclass = options.dev ? 'SvelteComponentDev' : 'SvelteComponent';
builder.addBlock(deindent`
class ${name} extends ${superclass} {
class ${name} extends @${superclass} {
constructor(options) {
super(${options.dev && `options`});
${should_add_css && `if (!document.getElementById("${component.stylesheet.id}-style")) @add_css();`}

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

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

@ -3,7 +3,7 @@ import * as fs from "fs";
import * as path from "path";
import { loadConfig, svelte } from "../helpers.js";
describe("js", () => {
describe.only("js", () => {
fs.readdirSync("test/js/samples").forEach(dir => {
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;
function a() {

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

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

@ -29,8 +29,8 @@ function create_fragment(component, ctx) {
},
p(changed, ctx) {
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 && !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 && !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...
let { buffered, seekable, played, currentTime, duration, paused, volume } = $$props;

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

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

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

Loading…
Cancel
Save