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

move render logic out of node objects #1746

Merged
merged 38 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
be84c96
put css/ under compile/
Rich-Harris Sep 15, 2018
7ef5f4f
move render logic to render-ssr
Rich-Harris Sep 16, 2018
cc7150d
remove ssr methods
Rich-Harris Sep 16, 2018
0c6682f
rename target -> renderer
Rich-Harris Sep 16, 2018
fa19cb3
snapshot of progress
Rich-Harris Sep 17, 2018
54045f4
get a few more tests passing
Rich-Harris Sep 18, 2018
cf5e039
start work on bindings
Rich-Harris Sep 19, 2018
2dce34c
merge master -> gh-1678
Rich-Harris Sep 19, 2018
e55a806
some progress
Rich-Harris Sep 20, 2018
bbce893
more
Rich-Harris Sep 20, 2018
dfa3d7f
implement slot
Rich-Harris Sep 20, 2018
69804ec
various
Rich-Harris Sep 20, 2018
d381294
some binding stuff
Rich-Harris Sep 20, 2018
62101cd
various
Rich-Harris Sep 20, 2018
84b5345
fix transitions and stuff
Rich-Harris Sep 21, 2018
81bf0fd
more fixes. almost there
Rich-Harris Sep 21, 2018
ec6bc6e
<svelte:head> and <title>
Rich-Harris Sep 21, 2018
bb304d0
various
Rich-Harris Sep 21, 2018
068ca71
fix addLoc
Rich-Harris Sep 21, 2018
0e45a75
fix event handler context
Rich-Harris Sep 22, 2018
9ef064e
fixes
Rich-Harris Sep 22, 2018
10255a9
fix indirect bindings
Rich-Harris Sep 22, 2018
ddf09b9
binding dependencies
Rich-Harris Sep 23, 2018
a80be70
fix toHTML
Rich-Harris Sep 23, 2018
10668fe
use textContent where appropriate
Rich-Harris Sep 23, 2018
71e6f13
update CLI tests
Rich-Harris Sep 23, 2018
7a18ee1
update some tests
Rich-Harris Sep 23, 2018
8f2f22b
minor fixes
Rich-Harris Sep 23, 2018
de23c5b
fix legacy input type
Rich-Harris Sep 23, 2018
60ab41f
more
Rich-Harris Sep 23, 2018
5dd44ea
almost all tests passing
Rich-Harris Sep 23, 2018
6b43892
remove some unused code
Rich-Harris Sep 23, 2018
503a95a
update test
Rich-Harris Sep 23, 2018
75f9bee
so close
Rich-Harris Sep 23, 2018
f4a87d0
holy shit all the tests are passing
Rich-Harris Sep 23, 2018
7e75e2d
abandon attempt to refactor bindings more aggressively
Rich-Harris Sep 23, 2018
2600acf
remove some unused code
Rich-Harris Sep 23, 2018
8708edf
more unused code
Rich-Harris Sep 23, 2018
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
25 changes: 8 additions & 17 deletions src/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import { walk, childKeys } from 'estree-walker';
import { getLocator } from 'locate-character';
import Stats from '../Stats';
import deindent from '../utils/deindent';
import CodeBuilder from '../utils/CodeBuilder';
import reservedNames from '../utils/reservedNames';
import namespaces from '../utils/namespaces';
import { removeNode } from '../utils/removeNode';
import nodeToString from '../utils/nodeToString';
import wrapModule from './wrapModule';
import annotateWithScopes from '../utils/annotateWithScopes';
import getName from '../utils/getName';
import Stylesheet from '../css/Stylesheet';
import Stylesheet from './css/Stylesheet';
import { test } from '../config';
import Fragment from './nodes/Fragment';
import shared from './shared';
import { DomTarget } from './dom';
import { SsrTarget } from './ssr';
import { Node, GenerateOptions, ShorthandImport, Ast, CompileOptions, CustomElementOptions } from '../interfaces';
import { Node, ShorthandImport, Ast, CompileOptions, CustomElementOptions } from '../interfaces';
import error from '../utils/error';
import getCodeFrame from '../utils/getCodeFrame';
import checkForComputedKeys from './validate/js/utils/checkForComputedKeys';
Expand Down Expand Up @@ -101,7 +98,6 @@ export default class Component {
name: string;
options: CompileOptions;
fragment: Fragment;
target: DomTarget | SsrTarget;

customElement: CustomElementOptions;
tag: string;
Expand All @@ -124,7 +120,6 @@ export default class Component {
hasComponents: boolean;
computations: Computation[];
templateProperties: Record<string, Node>;
slots: Set<string>;
javascript: [string, string];

used: {
Expand All @@ -142,13 +137,11 @@ export default class Component {

code: MagicString;

bindingGroups: string[];
indirectDependencies: Map<string, Set<string>>;
expectedProperties: Set<string>;
refs: Set<string>;

file: string;
fileVar: string;
locate: (c: number) => { line: number, column: number };

stylesheet: Stylesheet;
Expand All @@ -168,15 +161,13 @@ export default class Component {
source: string,
name: string,
options: CompileOptions,
stats: Stats,
target: DomTarget | SsrTarget
stats: Stats
) {
this.stats = stats;

this.ast = ast;
this.source = source;
this.options = options;
this.target = target;

this.imports = [];
this.shorthandImports = [];
Expand All @@ -188,7 +179,6 @@ export default class Component {
this.transitions = new Set();
this.actions = new Set();
this.importedComponents = new Map();
this.slots = new Set();

this.used = {
components: new Set(),
Expand All @@ -204,7 +194,6 @@ export default class Component {
this.refs = new Set();
this.refCallees = [];

this.bindingGroups = [];
this.indirectDependencies = new Map();

this.file = options.filename && (
Expand All @@ -229,8 +218,6 @@ export default class Component {
this.aliases = new Map();
this.usedNames = new Set();

this.fileVar = options.dev && this.getUniqueName('file');

this.computations = [];
this.templateProperties = {};
this.properties = new Map();
Expand Down Expand Up @@ -319,7 +306,11 @@ export default class Component {
return this.aliases.get(name);
}

generate(result: string, options: CompileOptions, { banner = '', name, format }: GenerateOptions ) {
generate(result: string, options: CompileOptions, {
banner = '',
name,
format
}) {
const pattern = /\[✂(\d+)-(\d+)$/;

const helpers = new Set();
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions src/css/Stylesheet.ts → src/compile/css/Stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import MagicString from 'magic-string';
import { walk } from 'estree-walker';
import { getLocator } from 'locate-character';
import Selector from './Selector';
import getCodeFrame from '../utils/getCodeFrame';
import hash from '../utils/hash';
import removeCSSPrefix from '../utils/removeCSSPrefix';
import Element from '../compile/nodes/Element';
import { Node, Ast, Warning } from '../interfaces';
import Component from '../compile/Component';
import getCodeFrame from '../../utils/getCodeFrame';
import hash from '../../utils/hash';
import removeCSSPrefix from '../../utils/removeCSSPrefix';
import Element from '../nodes/Element';
import { Node, Ast, Warning } from '../../interfaces';
import Component from '../Component';

const isKeyframesNode = (node: Node) => removeCSSPrefix(node.name) === 'keyframes'

Expand Down
17 changes: 8 additions & 9 deletions src/compile/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { assign } from '../shared';
import Stats from '../Stats';
import parse from '../parse/index';
import generate, { DomTarget } from './dom/index';
import generateSSR, { SsrTarget } from './ssr/index';
import renderDOM from './render-dom/index';
import renderSSR from './render-ssr/index';
import { CompileOptions, Warning, Ast } from '../interfaces';
import Component from './Component';

function normalize_options(options: CompileOptions): CompileOptions {
let normalized = assign({ generate: 'dom' }, options);
let normalized = assign({ generate: 'dom', dev: false }, options);
const { onwarn, onerror } = normalized;

normalized.onwarn = onwarn
Expand Down Expand Up @@ -74,20 +74,19 @@ export default function compile(source: string, options: CompileOptions) {
source,
options.name || 'SvelteComponent',
options,
stats,

// TODO make component generator-agnostic, to allow e.g. WebGL generator
options.generate === 'ssr' ? new SsrTarget() : new DomTarget()
stats
);
stats.stop('create component');

if (options.generate === false) {
return { ast, stats: stats.render(null), js: null, css: null };
}

const compiler = options.generate === 'ssr' ? generateSSR : generate;
if (options.generate === 'ssr') {
return renderSSR(component, options);
}

return compiler(component, options);
return renderDOM(component, options);
} catch (err) {
options.onerror(err);
return;
Expand Down
Loading