fix: do not generate unused-export-let inside <script context="module"> (#7232)

Fixes #7055. This warning can be delegated to userland tools like eslint
pull/7336/head
rgossiaux 3 years ago committed by GitHub
parent 9b7b8149e4
commit e2adf6a211
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -519,7 +519,7 @@ export default class Component {
return result; return result;
} }
private _extract_exports(node: ExportDefaultDeclaration | ExportNamedDeclaration | ExportAllDeclaration, module_script) { private _extract_exports(node: ExportDefaultDeclaration | ExportNamedDeclaration | ExportAllDeclaration, module_script: boolean) {
if (node.type === 'ExportDefaultDeclaration') { if (node.type === 'ExportDefaultDeclaration') {
return this.error(node as any, compiler_errors.default_export); return this.error(node as any, compiler_errors.default_export);
} }
@ -539,7 +539,7 @@ export default class Component {
extract_names(declarator.id).forEach(name => { extract_names(declarator.id).forEach(name => {
const variable = this.var_lookup.get(name); const variable = this.var_lookup.get(name);
variable.export_name = name; variable.export_name = name;
if (variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) { if (!module_script && variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) {
this.warn(declarator as any, compiler_warnings.unused_export_let(this.name.name, name)); this.warn(declarator as any, compiler_warnings.unused_export_let(this.name.name, name));
} }
}); });
@ -559,7 +559,7 @@ export default class Component {
if (variable) { if (variable) {
variable.export_name = specifier.exported.name; variable.export_name = specifier.exported.name;
if (variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) { if (!module_script && variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) {
this.warn(specifier as any, compiler_warnings.unused_export_let(this.name.name, specifier.exported.name)); this.warn(specifier as any, compiler_warnings.unused_export_let(this.name.name, specifier.exported.name));
} }
} }

@ -1,25 +1,48 @@
<script context="module">
var a1 = 1;
let b1 = 1;
const c1 = 1;
var d1 = 1;
let e1 = 1;
const f1 = 1;
export { d1, e1, f1};
export var g1 = 1;
export let h1 = 1;
export const i1 = 1;
export let j1 = () => {};
export const k1 = () => {};
export function l1() {};
var m1 = 1;
let n1 = 1;
const o1 = 1;
function foo1() {
return m1 + n1 + o1;
}
export let p1;
</script>
<script> <script>
var a = 1; var a2 = 1;
let b = 1; let b2 = 1;
const c = 1; const c2 = 1;
var d = 1; var d2 = 1;
let e = 1; let e2 = 1;
const f = 1; const f2 = 1;
export { d, e, f}; export { d2, e2, f2};
export var g = 1; export var g2 = 1;
export let h = 1; export let h2 = 1;
export const i = 1; export const i2 = 1;
export let j = () => {}; export let j2 = () => {};
export const k = () => {}; export const k2 = () => {};
export function l() {}; export function l2() {};
var m = 1; var m2 = 1;
let n = 1; let n2 = 1;
const o = 1; const o2 = 1;
function foo() { function foo2() {
return m + n + o; return m2 + n2 + o2;
} }
export let p; export let p2;
export let q; export let q2;
$p; $p2;
</script> </script>
{$q} {$q2}

@ -2,76 +2,76 @@
{ {
"code": "unused-export-let", "code": "unused-export-let",
"end": { "end": {
"character": 103, "character": 519,
"column": 12, "column": 13,
"line": 8 "line": 31
}, },
"message": "Component has unused export property 'd'. If it is for external reference only, please consider using `export const d`", "message": "Component has unused export property 'd2'. If it is for external reference only, please consider using `export const d2`",
"pos": 102, "pos": 517,
"start": { "start": {
"character": 102, "character": 517,
"column": 11, "column": 11,
"line": 8 "line": 31
} }
}, },
{ {
"code": "unused-export-let", "code": "unused-export-let",
"end": { "end": {
"character": 106, "character": 523,
"column": 15, "column": 17,
"line": 8 "line": 31
}, },
"message": "Component has unused export property 'e'. If it is for external reference only, please consider using `export const e`", "message": "Component has unused export property 'e2'. If it is for external reference only, please consider using `export const e2`",
"pos": 105, "pos": 521,
"start": { "start": {
"character": 105, "character": 521,
"column": 14, "column": 15,
"line": 8 "line": 31
} }
}, },
{ {
"code": "unused-export-let", "code": "unused-export-let",
"end": { "end": {
"character": 130, "character": 549,
"column": 18, "column": 19,
"line": 9 "line": 32
}, },
"message": "Component has unused export property 'g'. If it is for external reference only, please consider using `export const g`", "message": "Component has unused export property 'g2'. If it is for external reference only, please consider using `export const g2`",
"pos": 125, "pos": 543,
"start": { "start": {
"character": 125, "character": 543,
"column": 13, "column": 13,
"line": 9 "line": 32
} }
}, },
{ {
"code": "unused-export-let", "code": "unused-export-let",
"end": { "end": {
"character": 150, "character": 570,
"column": 18, "column": 19,
"line": 10 "line": 33
}, },
"message": "Component has unused export property 'h'. If it is for external reference only, please consider using `export const h`", "message": "Component has unused export property 'h2'. If it is for external reference only, please consider using `export const h2`",
"pos": 145, "pos": 564,
"start": { "start": {
"character": 145, "character": 564,
"column": 13, "column": 13,
"line": 10 "line": 33
} }
}, },
{ {
"code": "unused-export-let", "code": "unused-export-let",
"end": { "end": {
"character": 199, "character": 621,
"column": 25, "column": 26,
"line": 12 "line": 35
}, },
"message": "Component has unused export property 'j'. If it is for external reference only, please consider using `export const j`", "message": "Component has unused export property 'j2'. If it is for external reference only, please consider using `export const j2`",
"pos": 187, "pos": 608,
"start": { "start": {
"character": 187, "character": 608,
"column": 13, "column": 13,
"line": 12 "line": 35
} }
} }
] ]

Loading…
Cancel
Save