mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 03:05:12 +00:00
use devalue instead of serialize-javascript - fixes #112
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
"chalk": "^2.3.0",
|
||||
"cheerio": "^1.0.0-rc.2",
|
||||
"chokidar": "^1.7.0",
|
||||
"devalue": "^1.0.1",
|
||||
"glob": "^7.1.2",
|
||||
"mkdirp": "^0.5.1",
|
||||
"node-fetch": "^1.7.3",
|
||||
@@ -32,7 +33,6 @@
|
||||
"rimraf": "^2.6.2",
|
||||
"sade": "^1.4.0",
|
||||
"sander": "^0.6.0",
|
||||
"serialize-javascript": "^1.4.0",
|
||||
"source-map-support": "^0.5.3",
|
||||
"tslib": "^1.9.0",
|
||||
"url-parse": "^1.2.0",
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as path from 'path';
|
||||
import { ClientRequest, ServerResponse } from 'http';
|
||||
import mkdirp from 'mkdirp';
|
||||
import rimraf from 'rimraf';
|
||||
import serialize from 'serialize-javascript';
|
||||
import devalue from 'devalue';
|
||||
import { lookup } from './mime';
|
||||
import { create_routes, templates, create_compilers } from 'sapper/core.js';
|
||||
import { dest, dev } from '../config';
|
||||
@@ -331,7 +331,7 @@ function read_json(file: string) {
|
||||
|
||||
function try_serialize(data: any) {
|
||||
try {
|
||||
return serialize(data);
|
||||
return devalue(data);
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
|
||||
17
test/app/routes/preload-values/custom-class.html
Normal file
17
test/app/routes/preload-values/custom-class.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<h1>{{foo.bar()}}</h1>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
class Foo {
|
||||
bar() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
foo: new Foo()
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
11
test/app/routes/preload-values/set.html
Normal file
11
test/app/routes/preload-values/set.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<h1>{{set.has('x')}}</h1>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return {
|
||||
set: new Set(['x'])
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -487,6 +487,30 @@ function run(env) {
|
||||
assert.equal(title, `I'm afraid I just blue myself`);
|
||||
});
|
||||
});
|
||||
|
||||
it('serializes Set objects returned from preload', () => {
|
||||
return nightmare.goto(`${base}/preload-values/set`)
|
||||
.page.title()
|
||||
.then(title => {
|
||||
assert.equal(title, 'true');
|
||||
return nightmare.init().page.title();
|
||||
})
|
||||
.then(title => {
|
||||
assert.equal(title, 'true');
|
||||
});
|
||||
});
|
||||
|
||||
it('bails on custom classes returned from preload', () => {
|
||||
return nightmare.goto(`${base}/preload-values/custom-class`)
|
||||
.page.title()
|
||||
.then(title => {
|
||||
assert.equal(title, '42');
|
||||
return nightmare.init().page.title();
|
||||
})
|
||||
.then(title => {
|
||||
assert.equal(title, '42');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('headers', () => {
|
||||
|
||||
Reference in New Issue
Block a user