Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes handling of interpolated attributes
The isProp regular expression was insufficient as it only checked the preceding string, and if you had multiple values, the second preceding string would be a single space (attribute value delimiter). Now we run the regex starting from the end and working its way back to determine if we're in an attribute/property.
- Loading branch information
Showing
4 changed files
with
72 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { html } from '../../../lib/util/tagged-template'; | ||
import { cleanMemory } from '../../../lib/util/memory'; | ||
import validateMemory from '../../util/validateMemory'; | ||
|
||
describe('Unit: Tagged template', function() { | ||
afterEach(function() { | ||
cleanMemory(); | ||
validateMemory(); | ||
}); | ||
|
||
it('can interpolate a single string value in an attribute', function() { | ||
const foo = 'foo'; | ||
|
||
const multipleValues = html`<span class="${foo}" />`; | ||
|
||
assert.equal(multipleValues.attributes[0].name, 'class'); | ||
assert.equal(multipleValues.attributes[0].value, 'foo'); | ||
}); | ||
|
||
it('can interpolate multiple string values in an attribute', function() { | ||
const foo = 'foo'; | ||
const bar = 'bar'; | ||
|
||
const multipleValues = html`<span class="${foo} ${bar}" />`; | ||
|
||
assert.equal(multipleValues.attributes[0].name, 'class'); | ||
assert.equal(multipleValues.attributes[0].value, 'foo bar'); | ||
}); | ||
|
||
it('can interpolate multiple type values in an attribute', function() { | ||
const foo = 'foo'; | ||
const bar = {}; | ||
|
||
const multipleValues = html`<span class="${foo} ${bar}" />`; | ||
|
||
assert.equal(multipleValues.attributes[0].name, 'class'); | ||
assert.equal(multipleValues.attributes[0].value, 'foo __DIFFHTML__'); | ||
}); | ||
}); |