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);
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);
}

@ -1,21 +1,19 @@
import deindent from '../../utils/deindent';
import { stringify, escape } from '../../utils/stringify';
import CodeBuilder from '../../utils/CodeBuilder';
import globalWhitelist from '../../utils/globalWhitelist';
import Component from '../Component';
import Renderer from './Renderer';
import { CompileOptions } from '../../interfaces';
import { walk } from 'estree-walker';
import flattenReference from '../../utils/flattenReference';
export default function dom(
component: Component,
options: CompileOptions
) {
const format = options.format || 'esm';
const { name } = component;
const renderer = new Renderer(component, options);
const { block } = renderer;
block.hasOutroMethod = true;
@ -53,11 +51,6 @@ export default function dom(
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 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`
function create_fragment(${component.alias('component')}, ctx) {
${block.getContents()}

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