Skip to content

Add support for unqouted value of Quoted node #128

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

Merged
merged 1 commit into from
Feb 11, 2021
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
7 changes: 6 additions & 1 deletion docs/Quoted.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ Value: `'quoted'`
### `value`
Type: `String`<br>

The value of the string between the quote characters.
The value of the string between the quote characters, *including* quotes.

### `contents`
Type: `String`<br>

The value of the string between the quote characters, *without* quotes.

## Example Values

Expand Down
1 change: 1 addition & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export interface Quoted extends NodeBase {
parent: Container;
quote: string;
value: string;
contents: string;
}

export interface UnicodeRange extends NodeBase {
Expand Down
3 changes: 3 additions & 0 deletions lib/nodes/Quoted.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of this Source Code Form.
*/
const { unquote } = require('quote-unquote');

const { registerWalker } = require('../walker');

const Node = require('./Node');
Expand All @@ -16,6 +18,7 @@ class Quoted extends Node {
constructor(options) {
super(options);
this.type = 'quoted';
this.contents = unquote(options.value);
[this.quote] = options.value;
}

Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
],
"dependencies": {
"color-name": "^1.1.4",
"is-url-superb": "^4.0.0"
"is-url-superb": "^4.0.0",
"quote-unquote": "^1.0.0"
},
"devDependencies": {
"ava": "^3.12.1",
Expand Down
6 changes: 6 additions & 0 deletions test/snapshots/func.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -3127,6 +3127,7 @@ Generated by [AVA](https://avajs.dev).
name: 'url',
nodes: [
Quoted {
contents: '/gfx/img/bg.jpg',
parent: [Circular],
quote: '"',
raws: {
Expand Down Expand Up @@ -3206,6 +3207,7 @@ Generated by [AVA](https://avajs.dev).
name: 'url',
nodes: [
Quoted {
contents: 'http://domain.com/gfx/img/bg.jpg',
parent: [Circular],
quote: '"',
raws: {
Expand Down Expand Up @@ -3285,6 +3287,7 @@ Generated by [AVA](https://avajs.dev).
name: 'url',
nodes: [
Quoted {
contents: '/gfx/img/bg.jpg',
parent: [Circular],
quote: '\'',
raws: {
Expand Down Expand Up @@ -3364,6 +3367,7 @@ Generated by [AVA](https://avajs.dev).
name: 'url',
nodes: [
Quoted {
contents: 'http://domain.com/gfx/img/bg.jpg',
parent: [Circular],
quote: '\'',
raws: {
Expand Down Expand Up @@ -3678,6 +3682,7 @@ Generated by [AVA](https://avajs.dev).
name: 'url',
nodes: [
Quoted {
contents: '/gfx/img/bg.jpg',
parent: [Circular],
quote: '"',
raws: {
Expand Down Expand Up @@ -3790,6 +3795,7 @@ Generated by [AVA](https://avajs.dev).
name: 'url',
nodes: [
Quoted {
contents: 'http://domain.com/gfx/img/bg.jpg',
parent: [Circular],
quote: '"',
raws: {
Expand Down
Binary file modified test/snapshots/func.test.js.snap
Binary file not shown.
Binary file modified test/snapshots/numeric.test.js.snap
Binary file not shown.
Binary file modified test/snapshots/punctuation.test.js.snap
Binary file not shown.
2 changes: 2 additions & 0 deletions test/snapshots/word.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ Generated by [AVA](https://avajs.dev).
[Symbol(isClean)]: false,
},
Quoted {
contents: 'Open Sans',
quote: '\'',
raws: {
after: '',
Expand Down Expand Up @@ -1225,6 +1226,7 @@ Generated by [AVA](https://avajs.dev).
[Symbol(isClean)]: false,
},
Quoted {
contents: 'Helvetica Neue',
quote: '"',
raws: {
after: '',
Expand Down
Binary file modified test/snapshots/word.test.js.snap
Binary file not shown.