diff --git a/.eslintrc b/.eslintrc index df7882be4..0a1911d9d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -44,8 +44,8 @@ "no-array-constructor": "error", "no-class-assign": "error", "no-const-assign": "error", - "no-console": "warn", - "no-debugger": "warn", + "no-console": "error", + "no-debugger": "error", "no-dupe-args": "error", "no-dupe-class-members": "error", "no-dupe-keys": "error", diff --git a/lib/serializers/raw.js b/lib/serializers/raw.js index 685fa86b8..ae2b14ff1 100644 --- a/lib/serializers/raw.js +++ b/lib/serializers/raw.js @@ -480,7 +480,7 @@ const Raw = { */ untersifyBlock(object) { - if (object.isVoid) { + if (object.isVoid || !object.nodes || !object.nodes.length) { return { data: object.data, kind: object.kind, @@ -506,7 +506,7 @@ const Raw = { */ untersifyInline(object) { - if (object.isVoid) { + if (object.isVoid || !object.nodes || !object.nodes.length) { return { data: object.data, kind: object.kind, diff --git a/test/serializers/fixtures/html/deserialize/block-no-children/index.js b/test/serializers/fixtures/html/deserialize/block-no-children/index.js new file mode 100644 index 000000000..4f362bef4 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/block-no-children/index.js @@ -0,0 +1,25 @@ + +export default { + rules: [ + { + deserialize(el, next) { + switch (el.tagName) { + case 'p': { + return { + kind: 'block', + type: 'paragraph', + nodes: next(el.children) + } + } + case 'a': { + return { + kind: 'inline', + type: 'link', + nodes: next(el.children) + } + } + } + } + } + ] +} diff --git a/test/serializers/fixtures/html/deserialize/block-no-children/input.html b/test/serializers/fixtures/html/deserialize/block-no-children/input.html new file mode 100644 index 000000000..31ee88261 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/block-no-children/input.html @@ -0,0 +1 @@ +
diff --git a/test/serializers/fixtures/html/deserialize/block-no-children/output.yaml b/test/serializers/fixtures/html/deserialize/block-no-children/output.yaml new file mode 100644 index 000000000..337747150 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/block-no-children/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - type: paragraph + isVoid: false + data: {} + nodes: + - characters: [] diff --git a/test/serializers/fixtures/html/deserialize/inline-no-children/index.js b/test/serializers/fixtures/html/deserialize/inline-no-children/index.js new file mode 100644 index 000000000..4f362bef4 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/inline-no-children/index.js @@ -0,0 +1,25 @@ + +export default { + rules: [ + { + deserialize(el, next) { + switch (el.tagName) { + case 'p': { + return { + kind: 'block', + type: 'paragraph', + nodes: next(el.children) + } + } + case 'a': { + return { + kind: 'inline', + type: 'link', + nodes: next(el.children) + } + } + } + } + } + ] +} diff --git a/test/serializers/fixtures/html/deserialize/inline-no-children/input.html b/test/serializers/fixtures/html/deserialize/inline-no-children/input.html new file mode 100644 index 000000000..0fcb3e8e2 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/inline-no-children/input.html @@ -0,0 +1 @@ + diff --git a/test/serializers/fixtures/html/deserialize/inline-no-children/output.yaml b/test/serializers/fixtures/html/deserialize/inline-no-children/output.yaml new file mode 100644 index 000000000..337747150 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/inline-no-children/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - type: paragraph + isVoid: false + data: {} + nodes: + - characters: [] diff --git a/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/input.yaml b/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/input.yaml new file mode 100644 index 000000000..8a23705de --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/input.yaml @@ -0,0 +1,5 @@ + +nodes: + - kind: block + type: paragraph + nodes: [] diff --git a/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/output.yaml b/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/output.yaml new file mode 100644 index 000000000..337747150 --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - type: paragraph + isVoid: false + data: {} + nodes: + - characters: [] diff --git a/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/input.yaml b/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/input.yaml new file mode 100644 index 000000000..5db70fc35 --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/input.yaml @@ -0,0 +1,4 @@ + +nodes: + - kind: block + type: paragraph diff --git a/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/output.yaml b/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/output.yaml new file mode 100644 index 000000000..337747150 --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - type: paragraph + isVoid: false + data: {} + nodes: + - characters: []