-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
206 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"program": "${workspaceFolder}\\index.js" | ||
} | ||
] | ||
} |
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
10 changes: 10 additions & 0 deletions
10
test/svelte3/integration/locations/locations.multiscripts.svelte
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,10 @@ | ||
<h1>Template header</h1> | ||
<p>Template text</p> | ||
|
||
<script scope="module"> | ||
let staticVariable = 1; | ||
</script> | ||
|
||
<script> | ||
let variable = 1; | ||
</script> |
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,41 @@ | ||
const path = require('path'); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
|
||
const parser = require('../../../../index'); | ||
|
||
function assertDataItemLocation(dataItem, expectedLocationStart, expectedLocationEnd) { | ||
expect(dataItem.locations, `Code location for data item should be included for "${dataItem.name}"`).to.be.exist; | ||
expect(dataItem.locations.length, `Code location for data item have values for "${dataItem.name}"`).to.be.equal(1); | ||
const location = dataItem.locations[0]; | ||
expect(location, `Location should be correct identified for "${dataItem.name}"`).is.deep.equals({ start: expectedLocationStart, end: expectedLocationEnd }); | ||
} | ||
|
||
describe('SvelteDoc v3 - Locations', () => { | ||
it('Locations for multiple scripts should be found correct', (done) => { | ||
parser.parse({ | ||
version: 3, | ||
filename: path.resolve(__dirname, 'locations.multiscripts.svelte'), | ||
features: ['data'], | ||
includeSourceLocations: true, | ||
ignoredVisibilities: [] | ||
}).then((doc) => { | ||
expect(doc, 'Document should be provided').to.exist; | ||
expect(doc.data, 'Document events should be parsed').to.exist; | ||
|
||
const static = doc.data.find(p => p.name === 'staticVariable'); | ||
expect(static, '"staticVariable" should be presented in data items of the doc').to.exist; | ||
expect(static.static).to.be.true; | ||
assertDataItemLocation(static, 83, 97); | ||
|
||
const local = doc.data.find(p => p.name === 'variable'); | ||
expect(local, '"variable" should be presented in data items of the doc').to.exist; | ||
expect(local.static).to.be.false; | ||
assertDataItemLocation(local, 135, 143); | ||
|
||
done(); | ||
}).catch(e => { | ||
done(e); | ||
}); | ||
}); | ||
}); |
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,120 @@ | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
|
||
const helpers = require("../../../lib/helpers"); | ||
|
||
describe('Helpers parser module tests', () => { | ||
describe('helpers.extractHtmlBlock', () => { | ||
it('When html block exists should be provide a correct result', () => { | ||
const content = ` | ||
<p>Some content here</p> | ||
<script> | ||
let variable = 1; | ||
</script> | ||
`; | ||
|
||
const result = helpers.extractHtmlBlock(content, 'script'); | ||
|
||
expect(result).is.exist; | ||
const block = result.block; | ||
expect(block).is.exist; | ||
expect(block.content).is.eq('\nlet variable = 1;\n'); | ||
expect(block.offset).is.eq(34); | ||
expect(block.outerPosition).is.exist; | ||
expect(block.outerPosition.start).is.eq(26); | ||
expect(block.outerPosition.end).is.eq(62); | ||
expect(block.attributes).is.empty; | ||
}); | ||
|
||
it('When html block have attribute, should be correct extracted', () => { | ||
const content = ` | ||
<p>Some content here</p> | ||
<script scope="module"> | ||
let variable = 1; | ||
</script> | ||
`; | ||
|
||
const result = helpers.extractHtmlBlock(content, 'script'); | ||
|
||
expect(result).is.exist; | ||
const block = result.block; | ||
expect(block).is.exist; | ||
expect(block.attributes).is.eq(' scope="module"'); | ||
}); | ||
|
||
it('When startIndex are specified, should be skip first content and provide the next item', () => { | ||
const content = ` | ||
<p>Some content here</p> | ||
<script> | ||
let variable = 1; | ||
</script> | ||
<script> | ||
let variable = 2; | ||
</script> | ||
`; | ||
|
||
const result = helpers.extractHtmlBlock(content, 'script', 62); | ||
|
||
expect(result).is.exist; | ||
const block = result.block; | ||
expect(block).is.exist; | ||
expect(block.content).is.eq('\nlet variable = 2;\n'); | ||
expect(block.offset).is.eq(71); | ||
expect(block.outerPosition).is.exist; | ||
expect(block.outerPosition.start).is.eq(63); | ||
expect(block.outerPosition.end).is.eq(99); | ||
expect(block.attributes).is.empty; | ||
}); | ||
}); | ||
|
||
describe('helpers.extractAllHtmlBlocks', () => { | ||
it('Extract one script block', () => { | ||
const content = ` | ||
<p>Some content here</p> | ||
<script> | ||
let variable = 1; | ||
</script> | ||
`; | ||
const result = helpers.extractAllHtmlBlocks(content, 'script'); | ||
|
||
expect(result).is.exist; | ||
expect(result.blocks).is.exist; | ||
expect(result.blocks.length).is.eq(1); | ||
|
||
const block = result.blocks[0]; | ||
expect(block).is.exist; | ||
expect(block.offset).is.eq(34); | ||
expect(block.content).is.eq('\nlet variable = 1;\n'); | ||
expect(block.attributes).is.empty; | ||
}); | ||
|
||
it('Extract two script blocks', () => { | ||
const content = ` | ||
<p>Some content here</p> | ||
<script> | ||
let variable = 1; | ||
</script> | ||
<script> | ||
let variable = 2; | ||
</script> | ||
`; | ||
const result = helpers.extractAllHtmlBlocks(content, 'script'); | ||
|
||
expect(result).is.exist; | ||
expect(result.blocks).is.exist; | ||
expect(result.blocks.length).is.eq(2); | ||
|
||
let block = result.blocks[0]; | ||
expect(block).is.exist; | ||
expect(block.offset).is.eq(34); | ||
expect(block.content).is.eq('\nlet variable = 1;\n'); | ||
expect(block.attributes).is.empty; | ||
|
||
block = result.blocks[1]; | ||
expect(block).is.exist; | ||
expect(block.offset).is.eq(71); | ||
expect(block.content).is.eq('\nlet variable = 2;\n'); | ||
expect(block.attributes).is.empty; | ||
}); | ||
}); | ||
}); |