do instrumentation in render-dom

pull/1839/head
Rich Harris 7 years ago
parent ceb37e06e5
commit 6060a308ad

@ -536,30 +536,6 @@ export default class Component {
this.extract_imports_and_exports(script.content, this.imports, this.exports); this.extract_imports_and_exports(script.content, this.imports, this.exports);
const top_scope = scope;
walk(script.content, {
enter: (node, parent) => {
if (map.has(node)) {
scope = map.get(node);
}
if (node.type === 'AssignmentExpression') {
const { name } = flattenReference(node.left);
if (scope.findOwner(name) === top_scope) {
this.instrument(node, parent, name, false);
}
}
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
}
});
this.javascript = this.extract_javascript(script); this.javascript = this.extract_javascript(script);
} }

@ -1,21 +1,19 @@
import deindent from '../../utils/deindent'; import deindent from '../../utils/deindent';
import { stringify, escape } from '../../utils/stringify'; import { stringify, escape } from '../../utils/stringify';
import CodeBuilder from '../../utils/CodeBuilder'; import CodeBuilder from '../../utils/CodeBuilder';
import globalWhitelist from '../../utils/globalWhitelist';
import Component from '../Component'; import Component from '../Component';
import Renderer from './Renderer'; import Renderer from './Renderer';
import { CompileOptions } from '../../interfaces'; import { CompileOptions } from '../../interfaces';
import { walk } from 'estree-walker';
import flattenReference from '../../utils/flattenReference';
export default function dom( export default function dom(
component: Component, component: Component,
options: CompileOptions options: CompileOptions
) { ) {
const format = options.format || 'esm';
const { name } = component; const { name } = component;
const renderer = new Renderer(component, options); const renderer = new Renderer(component, options);
const { block } = renderer; const { block } = renderer;
block.hasOutroMethod = true; block.hasOutroMethod = true;
@ -53,11 +51,6 @@ export default function dom(
builder.addBlock(block.toString()); builder.addBlock(block.toString());
}); });
const debugName = `<${component.customElement ? component.tag : name}>`;
const expectedProperties = Array.from(component.expectedProperties);
const globals = expectedProperties.filter(prop => globalWhitelist.has(prop));
const refs = Array.from(component.refs); const refs = Array.from(component.refs);
const superclass = component.alias(options.dev ? 'SvelteComponentDev' : 'SvelteComponent'); const superclass = component.alias(options.dev ? 'SvelteComponentDev' : 'SvelteComponent');
@ -148,6 +141,34 @@ export default function dom(
} }
} }
// instrument assignments
if (component.instance_script) {
let scope = component.instance_scope;
let map = component.instance_scope_map;
walk(component.instance_script.content, {
enter: (node, parent) => {
if (map.has(node)) {
scope = map.get(node);
}
if (node.type === 'AssignmentExpression') {
const { name } = flattenReference(node.left);
if (scope.findOwner(name) === component.instance_scope) {
component.instrument(node, parent, name, false);
}
}
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
}
});
}
builder.addBlock(deindent` builder.addBlock(deindent`
function create_fragment(${component.alias('component')}, ctx) { function create_fragment(${component.alias('component')}, ctx) {
${block.getContents()} ${block.getContents()}

@ -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