Skip to content
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

Vue.js mustach not correctly rendered only after indenting root element #8103

Closed
DanielSharkov opened this issue Apr 29, 2018 · 4 comments
Closed

Comments

@DanielSharkov
Copy link

DanielSharkov commented Apr 29, 2018

Version

2.5.16

Reproduction link

https://codesandbox.io/s/6jnlpno3lw

Steps to reproduce

This issue happens, when the root element is not indented and the mustache is split into several lines.

<template>
<div>
	<p>{{
		myVar
	}}</p>
</div>
</template>

Only when the root element is indented, the mustache gets rendered correctly.

<template>
	<div>
		<p>{{
			myVar
		}}</p>
	</div>
</template>

What also works, is when mustache is put into a single line and the root element is not indented.

<template>
<div>
	<p>{{ myVar }}</p>
</div>
</template>

What is expected?

The mustache should bind data

What is actually happening?

The mustache gets rendered plain text


Only wanted to prettify my code, so I split the mustache into several lines and removed the indent of the root element.

@Alexander-Taran
Copy link

does work with a single space between <template> and root element:

<template> <p>{{
  myVar
}}</p></template>

does not with no space between them:

<template><p>{{ 
  myVar
}}</p></template>

@syntacticsolutions
Copy link

Why would anyone write their code that way?

@DanielSharkov
Copy link
Author

DanielSharkov commented May 8, 2018

@syntacticsolutions This doesn't matter, fact is it's a bug, right?

@defcc
Copy link
Member

defcc commented May 9, 2018

Thanks @DanielSharkov , it should be a bug.

The root cause of different behavior with indent is bellow: https://github.com/yyx990803/de-indent/blob/master/index.js#L17-L24

    if (c === ' ' || c === '\t') {
      type = c
      cur = count(line, type)
      if (cur < min) {
        min = cur
      }
    } else {
      return str

Maybe we should add \r? pattern in the text interpolation regexp:

const defaultTagRE = /\{\{((?:.|\n)+?)\}\}/g
const regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g
const buildRegex = cached(delimiters => {
const open = delimiters[0].replace(regexEscapeRE, '\\$&')
const close = delimiters[1].replace(regexEscapeRE, '\\$&')
return new RegExp(open + '((?:.|\\n)+?)' + close, 'g')
})

@defcc defcc added the bug label May 9, 2018
@vuejs vuejs deleted a comment from lingchenzheng Jun 1, 2018
haoqunjiang added a commit to haoqunjiang/vue that referenced this issue Jun 25, 2018
f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants