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

v2 #1348

Merged
merged 42 commits into from
Apr 19, 2018
Merged

v2 #1348

Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
470eacf
remove obsolete methods
Rich-Harris Apr 15, 2018
34d2fbf
remove ES5 constraint
Rich-Harris Apr 15, 2018
7b40fed
remove unused store methods
Rich-Harris Apr 15, 2018
9070969
remove references to obsolete methods
Rich-Harris Apr 15, 2018
9bc8b74
update store tests
Rich-Harris Apr 15, 2018
daa2635
update snapshot tests
Rich-Harris Apr 15, 2018
2f86bd3
update tests to account for removal of observe
Rich-Harris Apr 15, 2018
df4e367
update snapshot tests
Rich-Harris Apr 15, 2018
a3add04
remove code, map and cssMap from svelte.compile output
Rich-Harris Apr 15, 2018
80e0dce
remove validate and Stylesheet from public API
Rich-Harris Apr 15, 2018
4fe8d95
dont typecast numeric attributes
Rich-Harris Apr 16, 2018
21168bf
remove v1 parser tests
Rich-Harris Apr 16, 2018
286caba
oops
Rich-Harris Apr 16, 2018
ab79cc6
remove v1 snapshot tests
Rich-Harris Apr 16, 2018
ce11460
remove deprecated renderCss method
Rich-Harris Apr 16, 2018
4b3da75
remove v1 runtime tests
Rich-Harris Apr 16, 2018
1143b0a
remove v1 tests
Rich-Harris Apr 16, 2018
2d5b47b
remove store option
Rich-Harris Apr 16, 2018
39ad124
update validation tests
Rich-Harris Apr 16, 2018
8eb4adc
small fix
Rich-Harris Apr 16, 2018
a275960
SSR tests
Rich-Harris Apr 16, 2018
39d0b86
update hydration tests
Rich-Harris Apr 16, 2018
40e6b4f
update css tests
Rich-Harris Apr 16, 2018
87a8e37
remove cascade option
Rich-Harris Apr 16, 2018
cae4dd9
fix some more tests
Rich-Harris Apr 16, 2018
73e83e5
tidy up
Rich-Harris Apr 16, 2018
dadf21c
skip test, fix post-v2
Rich-Harris Apr 16, 2018
d2a5b36
remove redundant test
Rich-Harris Apr 16, 2018
a32c2ba
Merge branch 'master' into v2
Rich-Harris Apr 17, 2018
7e733d8
enforce uppercase component names
Rich-Harris Apr 17, 2018
b9fcc16
update test
Rich-Harris Apr 17, 2018
07bad96
tidy up
Rich-Harris Apr 17, 2018
5a457bf
rename loc to start, include character info in locations
Rich-Harris Apr 17, 2018
69c41a0
use new Function instead of eval, to prevent Rollup complaining
Rich-Harris Apr 17, 2018
a2d3d05
merge master -> v2
Rich-Harris Apr 18, 2018
da6fa85
update README
Rich-Harris Apr 18, 2018
1e9b32a
fixes
Rich-Harris Apr 18, 2018
f2b6ec4
fix <svelte:window> to use new APIs
Conduitry Apr 18, 2018
06517ce
remove erroneous warnings
Rich-Harris Apr 18, 2018
fb9d7cd
remove obsolete hash stuff
Rich-Harris Apr 18, 2018
6ff02b2
remove legacy prop stuff, now that we emit ES2015
Rich-Harris Apr 18, 2018
aaab685
support $method(...) calls, and warn on store.method(...)
Rich-Harris Apr 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 12 additions & 1 deletion src/Stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@ function collapseTimings(timings) {
}

export default class Stats {
onwarn: (warning: Warning) => void;

startTime: number;
currentTiming: Timing;
currentChildren: Timing[];
timings: Timing[];
stack: Timing[];
warnings: Warning[];

constructor() {
constructor({ onwarn }: {
onwarn: (warning: Warning) => void
}) {
this.startTime = now();
this.stack = [];
this.currentChildren = this.timings = [];

this.onwarn = onwarn;

this.warnings = [];
}

Expand Down Expand Up @@ -99,4 +105,9 @@ export default class Stats {
hooks
};
}

warn(warning) {
this.warnings.push(warning);
this.onwarn(warning);
}
}
20 changes: 1 addition & 19 deletions src/generators/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,31 +369,13 @@ export default class Generator {
})
};

Object.getOwnPropertyNames(String.prototype).forEach(name => {
const descriptor = Object.getOwnPropertyDescriptor(String.prototype, name);
if (typeof descriptor.value === 'function') {
Object.defineProperty(css, name, {
value: (...args) => {
return css.code === null
? null
: css.code[name].call(css.code, ...args);
}
});
}
});

this.stats.stop('compile');

return {
ast: this.ast,
js,
css,
stats: this.stats.render(this),

// TODO deprecate
code: js.code,
map: js.map,
cssMap: css.map
stats: this.stats.render(this)
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/generators/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export default function dom(
? `@proto`
: deindent`
{
${['destroy', 'get', 'fire', 'observe', 'on', 'set', 'teardown', '_set', '_mount', '_unmount', '_differs']
.map(n => `${n}: @${n === 'teardown' ? 'destroy' : n}`)
${['destroy', 'get', 'fire', 'on', 'set', '_set', '_mount', '_unmount', '_differs']
.map(n => `${n}: @${n}`)
.join(',\n')}
}`;

Expand Down Expand Up @@ -294,7 +294,7 @@ export default function dom(

${props.map(prop => deindent`
get ${prop}() {
return this.get('${prop}');
return this.get().${prop};
}

set ${prop}(value) {
Expand Down
10 changes: 1 addition & 9 deletions src/generators/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,16 +580,8 @@ export default class Element extends Node {
});
`);

if (generator.options.dev) {
block.builders.hydrate.addBlock(deindent`
if (${handlerName}.teardown) {
console.warn("Return 'destroy()' from custom event handlers. Returning 'teardown()' has been deprecated and will be unsupported in Svelte 2");
}
`);
}

block.builders.destroy.addLine(deindent`
${handlerName}[${handlerName}.destroy ? 'destroy' : 'teardown']();
${handlerName}.destroy();
`);
} else {
const handler = deindent`
Expand Down
10 changes: 1 addition & 9 deletions src/generators/nodes/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,8 @@ export default class Window extends Node {
});
`);

if (generator.options.dev) {
block.builders.hydrate.addBlock(deindent`
if (${handlerName}.teardown) {
console.warn("Return 'destroy()' from custom event handlers. Returning 'teardown()' has been deprecated and will be unsupported in Svelte 2");
}
`);
}

block.builders.destroy.addLine(deindent`
${handlerName}[${handlerName}.destroy ? 'destroy' : 'teardown']();
${handlerName}.destroy();
`);
} else {
block.builders.init.addBlock(deindent`
Expand Down
2 changes: 1 addition & 1 deletion src/generators/nodes/shared/mungeAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function mungeAttribute(attribute: Node, block: Block): MungedAtt
return {
spread: false,
name: attribute.name,
value: isNaN(value.data) ? stringify(value.data) : value.data,
value: stringify(value.data),
dynamic: false,
dependencies: []
};
Expand Down
41 changes: 0 additions & 41 deletions src/generators/server-side-rendering/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,47 +163,6 @@ export default function ssr(
};

var warned = false;
${name}.renderCss = function() {
if (!warned) {
console.error('Component.renderCss(...) is deprecated and will be removed in v2 — use Component.render(...).css instead');
warned = true;
}

var components = [];

${generator.stylesheet.hasStyles &&
deindent`
components.push({
filename: ${name}.filename,
css: ${name}.css && ${name}.css.code,
map: ${name}.css && ${name}.css.map
});
`}

${templateProperties.components &&
deindent`
var seen = {};

function addComponent(component) {
var result = component.renderCss();
result.components.forEach(x => {
if (seen[x.filename]) return;
seen[x.filename] = true;
components.push(x);
});
}

${templateProperties.components.value.properties.map((prop: Node) => {
return `addComponent(%components-${getName(prop.key)});`;
})}
`}

return {
css: components.map(x => x.css).join('\\n'),
map: null,
components
};
};

${templateProperties.preload && `${name}.preload = %preload;`}

Expand Down
2 changes: 1 addition & 1 deletion src/generators/server-side-rendering/visitors/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function visitComponent(
if (attribute.value.length === 1) {
const chunk = attribute.value[0];
if (chunk.type === 'Text') {
return isNaN(chunk.data) ? stringify(chunk.data) : chunk.data;
return stringify(chunk.data);
}

block.contextualise(chunk.expression);
Expand Down
28 changes: 13 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ export async function preprocess(source: string, options: PreprocessOptions) {
};
}

export function compile(source: string, _options: CompileOptions) {
function compile(source: string, _options: CompileOptions) {
const options = normalizeOptions(_options);
let parsed: Parsed;

const stats = new Stats();
const stats = new Stats({
onwarn: options.onwarn
});

try {
stats.start('parse');
Expand All @@ -126,33 +128,29 @@ export function compile(source: string, _options: CompileOptions) {
stats.stop('stylesheet');

stats.start('validate');
// TODO remove this when we remove svelte.validate from public API — we
// can use the stats object instead
const onwarn = options.onwarn;
options.onwarn = warning => {
stats.warnings.push(warning);
onwarn(warning);
};

validate(parsed, source, stylesheet, options);
validate(parsed, source, stylesheet, stats, options);
stats.stop('validate');

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

const compiler = options.generate === 'ssr' ? generateSSR : generate;

return compiler(parsed, source, stylesheet, options, stats);
};

export function create(source: string, _options: CompileOptions = {}) {
function create(source: string, _options: CompileOptions = {}) {
_options.format = 'eval';

const compiled = compile(source, _options);

if (!compiled || !compiled.code) {
if (!compiled || !compiled.js.code) {
return;
}

try {
return (0, eval)(compiled.code);
return (0, eval)(compiled.js.code);
} catch (err) {
if (_options.onerror) {
_options.onerror(err);
Expand All @@ -163,4 +161,4 @@ export function create(source: string, _options: CompileOptions = {}) {
}
}

export { parse, validate, Stylesheet, version as VERSION };
export { parse, create, compile, version as VERSION };
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface CompileOptions {
format?: ModuleFormat;
name?: string;
filename?: string;
generate?: string;
generate?: string | false;
globals?: ((id: string) => string) | object;
amd?: {
id?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/server-side-rendering/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function _register(extension) {
generate: 'ssr'
});

const {code} = compile(fs.readFileSync(filename, 'utf-8'), options);
const { js } = compile(fs.readFileSync(filename, 'utf-8'), options);

return module._compile(code, filename);
return module._compile(js.code, filename);
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"plugin:import/warnings"
],
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 9,
"sourceType": "module"
},
"settings": {
Expand Down
7 changes: 1 addition & 6 deletions src/shared/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ fs.readdirSync(__dirname).forEach(file => {

const source = fs.readFileSync(path.join(__dirname, file), 'utf-8');
const ast = acorn.parse(source, {
ecmaVersion: 6,
ecmaVersion: 9,
sourceType: 'module'
});

ast.body.forEach(node => {
if (node.type !== 'ExportNamedDeclaration') return;

// check no ES6+ slipped in
acorn.parse(source.slice(node.declaration.start, node.end), {
ecmaVersion: 5
});

const declaration = node.declaration;
if (!declaration) return;

Expand Down
Loading