Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions lib/nodes/Quoted.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ class Quoted extends Node {
constructor(options) {
super(options);
this.type = 'quoted';
this.contents = unquote(options.value);
[this.quote] = options.value;
/**
* When cloning the node via {@link Node.clone()} there are no constructor params
*/
if (options && options.value) {
this.contents = unquote(options.value);
[this.quote] = options.value;
}
}

static fromTokens(tokens, parser) {
Expand Down
57 changes: 57 additions & 0 deletions test/quoted.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright © 2018 Andrew Powell

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of this Source Code Form.
*/
const test = require('ava');

const { nodeToString, parse } = require('../lib');

const { snapshot, throws } = require('./fixtures/quoted');

for (const fixture of snapshot) {
test(fixture, (t) => {
const root = parse(fixture);
const nodes = root.nodes.map((node) => {
delete node.parent; // eslint-disable-line no-param-reassign
return node;
});
const string = nodeToString(root);

t.is(string, fixture);
t.is(fixture, root.toString());
t.snapshot(root.first.toString());
t.snapshot(string);
t.snapshot(nodes);

root.clone();
});

test(`${fixture} be should cloned`, (t) => {
const root = parse(fixture);
const nodes = root.nodes.map((node) => {
delete node.parent; // eslint-disable-line no-param-reassign
return node;
});
const string = nodeToString(root);

const cloned = root.clone();

t.is(string, fixture);
t.is(fixture, root.toString());
t.snapshot(cloned.first.toString());
t.snapshot(string);
t.snapshot(nodes);
});
}

for (const fixture of throws) {
test(fixture, (t) => {
t.throws(() => parse(fixture));
});
}
Loading