Skip to content

Commit

Permalink
Merge pull request #73 from ekhaled/module-scope-correction
Browse files Browse the repository at this point in the history
fix #72: Use of "context" instead of "scope" when parsing module scripts
  • Loading branch information
alexprey authored Aug 27, 2021
2 parents 02c7ac1 + 694d83b commit 2472b5a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/v3/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const { ScriptEvent } = require('./events');
*/

const RE_ANONYMOUS_FUNCTION = /^{?\s*function\s+\(/i;
const RE_STATIC_SCOPE = /\sscope=('module'|"module")/gi;
const RE_STATIC_SCOPE = /\scontext=('module'|"module")/gi;

/** @typedef {'default' | 'static' | 'markup'} ScopeType */

Expand Down
2 changes: 1 addition & 1 deletion test/svelte3/integration/data/data.static.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<script scope="module">
<script context="module">
let staticVariable = 1;
</script>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Template header</h1>
<p>Template text</p>

<script scope="module">
<script context="module">
let staticVariable = 1;
</script>

Expand Down
4 changes: 2 additions & 2 deletions test/svelte3/integration/locations/locations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ describe('SvelteDoc v3 - Locations', () => {

expect(staticVariable, '"staticVariable" should be presented in data items of the doc').to.exist;
expect(staticVariable.static).to.be.true;
assertDataItemLocation(staticVariable, 79, 93);
assertDataItemLocation(staticVariable, 81, 95);

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, 127, 135);
assertDataItemLocation(local, 129, 137);

done();
}).catch(e => {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/helpers/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let variable = 1;
it('When html block have attribute, should be correct extracted', () => {
const content = `
<p>Some content here</p>
<script scope="module">
<script context="module">
let variable = 1;
</script>
`;
Expand All @@ -41,7 +41,7 @@ let variable = 1;
const block = result.block;

expect(block).is.exist;
expect(block.attributes).is.eq(' scope="module"');
expect(block.attributes).is.eq(' context="module"');
});

it('When startIndex are specified, should be skip first content and provide the next item', () => {
Expand Down Expand Up @@ -138,7 +138,7 @@ export let items = [];
<Code>
{@html highlight(
'<script> \n' +
' const items = [ \n' +
' const items = [ \n' +
' { title: "Tab 1", active: true }, \n' +
' { title: "Tab 2", active: false }, \n' +
' { title: "Tab 3", active: false }, \n' +
Expand Down
10 changes: 5 additions & 5 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface JSDocTypeElement extends JSDocTypeBase {
/**
* Provide the path from where this event are imported.
* Emited only if JSDoc have {import()} statement.
*
*
* @example
* For example, lets check the following JSDoc comment:
* ```js
Expand Down Expand Up @@ -143,7 +143,7 @@ export interface SvelteDataItem extends ISvelteItem {
bind?: SvelteDataBindMapping[];
/**
* Indicates that this data item of component located in static context.
* Variable should be declared in `<script scope="module" />` block.
* Variable should be declared in `<script context="module" />` block.
* @since Svelte V3
* @since {2.0.0}
*/
Expand Down Expand Up @@ -225,7 +225,7 @@ export interface SvelteMethodParamItem {
description?: string;
/**
* Indicates that this data item of component located in static context.
* Variable should be declared in `<script scope="module" />` block.
* Variable should be declared in `<script context="module" />` block.
* @since Svelte V3
* @since {2.0.0}
*/
Expand Down Expand Up @@ -531,7 +531,7 @@ export type SvelteParserOptions =
declare module 'sveltedoc-parser' {
/**
* Parse the svelte source file to structured object.
*
*
* @param options The parser options
* @example
* ```js
Expand All @@ -554,7 +554,7 @@ declare module 'sveltedoc-parser' {

/**
* Try to detect svelte source file version.
*
*
* @param options The parser options
* @return The detected version of svelte source file.
*/
Expand Down

0 comments on commit 2472b5a

Please sign in to comment.