Skip to content

Commit

Permalink
fix(compiler): should not condense  
Browse files Browse the repository at this point in the history
fix #945
  • Loading branch information
yyx990803 committed Apr 8, 2020
1 parent be666eb commit 8c17535
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function parseChildren(
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i]
if (node.type === NodeTypes.TEXT) {
if (!node.content.trim()) {
if (!/[^\t\r\n\f ]/.test(node.content)) {
const prev = nodes[i - 1]
const next = nodes[i + 1]
// If:
Expand All @@ -219,7 +219,7 @@ function parseChildren(
node.content = ' '
}
} else {
node.content = node.content.replace(/\s+/g, ' ')
node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ')
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions packages/compiler-dom/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
InterpolationNode
} from '@vue/compiler-core'
import {
parserOptionsMinimal as parserOptions,
parserOptionsStandard as parserOptions,
DOMNamespaces
} from '../src/parserOptionsMinimal'
} from '../src/parserOptionsStandard'

describe('DOM parser', () => {
describe('Text', () => {
Expand Down Expand Up @@ -160,6 +160,16 @@ describe('DOM parser', () => {
}
])
})

// #945
test('&nbsp; should not be condensed', () => {
const nbsp = String.fromCharCode(160)
const ast = parse(`foo&nbsp;&nbsp;bar`, parserOptions)
expect(ast.children[0]).toMatchObject({
type: NodeTypes.TEXT,
content: `foo${nbsp}${nbsp}bar`
})
})
})

describe('Interpolation', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler-dom/src/parserOptionsStandard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ParserOptions } from '@vue/compiler-core'
import { parserOptionsMinimal } from './parserOptionsMinimal'
import namedCharacterReferences from './namedChars.json'

export { DOMNamespaces } from './parserOptionsMinimal'

export const parserOptionsStandard: ParserOptions = {
// extends the minimal options with more spec-compliant overrides
...parserOptionsMinimal,
Expand Down

0 comments on commit 8c17535

Please sign in to comment.