remove svelte.parse and svelte.create from public API. dont see a way to support svelte.create in v3

pull/1839/head
Rich Harris 7 years ago
parent ed23d7acb3
commit a20bbc442e

@ -1,19 +1,4 @@
import compile from './compile/index';
import { CompileOptions } from './interfaces';
export function create(source: string, options: CompileOptions = {}) {
options.format = 'eval';
const compiled = compile(source, options);
if (!compiled || !compiled.js.code) {
return;
}
return (new Function(`return ${compiled.js.code}`))();
}
export { default as compile } from './compile/index';
export { default as parse } from './parse/index';
export { default as preprocess } from './preprocess/index';
export const VERSION = '__VERSION__';

@ -1,15 +0,0 @@
import assert from "assert";
import { svelte, deindent } from "../helpers.js";
describe("create", () => {
it("should return a component constructor", () => {
const component = svelte.create(`<div>{prop}</div>`);
assert(component instanceof Function);
});
it("should throw error when source is invalid ", done => {
assert.throws(() => {
svelte.create(`<div>{prop</div>`);
}, /TODO/);
});
});

@ -3,7 +3,7 @@ import * as fs from "fs";
import * as path from "path";
import { loadConfig, svelte } from "../helpers.js";
describe.only("js", () => {
describe("js", () => {
fs.readdirSync("test/js/samples").forEach(dir => {
if (dir[0] === ".") return;

@ -23,13 +23,15 @@ describe('parse', () => {
const expectedError = tryToLoadJson(`test/parser/samples/${dir}/error.json`);
try {
const actual = svelte.parse(input, options);
const { ast } = svelte.compile(input, Object.assign(options, {
generate: false
}));
fs.writeFileSync(`test/parser/samples/${dir}/_actual.json`, JSON.stringify(actual, null, '\t'));
fs.writeFileSync(`test/parser/samples/${dir}/_actual.json`, JSON.stringify(ast, null, '\t'));
assert.deepEqual(actual.html, expectedOutput.html);
assert.deepEqual(actual.css, expectedOutput.css);
assert.deepEqual(actual.js, expectedOutput.js);
assert.deepEqual(ast.html, expectedOutput.html);
assert.deepEqual(ast.css, expectedOutput.css);
assert.deepEqual(ast.js, expectedOutput.js);
} catch (err) {
if (err.name !== 'ParseError') throw err;
if (!expectedError) throw err;
@ -47,12 +49,4 @@ describe('parse', () => {
}
});
});
it('includes AST in svelte.compile output', () => {
const source = fs.readFileSync(`test/parser/samples/attribute-dynamic/input.html`, 'utf-8');
const { ast } = svelte.compile(source);
const parsed = svelte.parse(source);
assert.deepEqual(ast, parsed);
});
});

Loading…
Cancel
Save