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

feat(common): Add contexts to the error messages #6526

Merged
merged 24 commits into from Nov 28, 2022
  •  
  •  
  •  
@@ -1,7 +1,11 @@
//// [1.0lib-noErrors.ts]
//!
//! x 'eval' and 'arguments' cannot be used as a binding identifier in strict mode
//! ,----
//! ,-[27:1]
//! 27 | * @param x A String value that contains valid JavaScript code.
//! 28 | */
//! 29 | declare function eval(x: string): any;
//! : ^^^^
//! 30 |
//! 31 | /**
//! `----
@@ -1,7 +1,11 @@
//// [1.0lib-noErrors.ts]
//!
//! x 'eval' and 'arguments' cannot be used as a binding identifier in strict mode
//! ,----
//! ,-[27:1]
//! 27 | * @param x A String value that contains valid JavaScript code.
//! 28 | */
//! 29 | declare function eval(x: string): any;
//! : ^^^^
//! 30 |
//! 31 | /**
//! `----
10 changes: 7 additions & 3 deletions crates/swc/tests/tsc-references/ES5For-of20.1.normal.js
@@ -1,7 +1,11 @@
//// [ES5For-of20.ts]
//!
//! x 'const' declarations must be initialized
//! ,----
//! 4 | const v;
//! : ^
//! ,-[2:1]
//! 2 | let v;
//! 3 | for (let v of [v]) {
//! 4 | const v;
//! : ^
//! 5 | }
//! 6 | }
//! `----
10 changes: 7 additions & 3 deletions crates/swc/tests/tsc-references/ES5For-of20.2.minified.js
@@ -1,7 +1,11 @@
//// [ES5For-of20.ts]
//!
//! x 'const' declarations must be initialized
//! ,----
//! 4 | const v;
//! : ^
//! ,-[2:1]
//! 2 | let v;
//! 3 | for (let v of [v]) {
//! 4 | const v;
//! : ^
//! 5 | }
//! 6 | }
//! `----
@@ -1,7 +1,8 @@
//// [FunctionDeclaration11_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function * yield() {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,7 +1,8 @@
//// [FunctionDeclaration11_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function * yield() {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,7 +1,8 @@
//// [FunctionDeclaration2_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function f(yield) {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,7 +1,8 @@
//// [FunctionDeclaration2_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function f(yield) {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,14 +1,16 @@
//// [FunctionDeclaration3_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function f(yield = yield) {
//! : ^^^^^
//! 2 | }
//! `----
//!
//! x Unexpected token `yield`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp,
//! | ` for template literal, (, or an identifier
//! ,----
//! ,-[1:1]
//! 1 | function f(yield = yield) {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,14 +1,16 @@
//// [FunctionDeclaration3_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function f(yield = yield) {
//! : ^^^^^
//! 2 | }
//! `----
//!
//! x Unexpected token `yield`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp,
//! | ` for template literal, (, or an identifier
//! ,----
//! ,-[1:1]
//! 1 | function f(yield = yield) {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,7 +1,8 @@
//// [FunctionDeclaration4_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function yield() {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,7 +1,8 @@
//// [FunctionDeclaration4_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function yield() {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,13 +1,15 @@
//// [FunctionDeclaration5_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function*foo(yield) {
//! : ^^^^^
//! 2 | }
//! `----
//!
//! x Expected ident
//! ,----
//! ,-[1:1]
//! 1 | function*foo(yield) {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,13 +1,15 @@
//// [FunctionDeclaration5_es6.ts]
//!
//! x `yield` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | function*foo(yield) {
//! : ^^^^^
//! 2 | }
//! `----
//!
//! x Expected ident
//! ,----
//! ,-[1:1]
//! 1 | function*foo(yield) {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,7 +1,8 @@
//// [FunctionDeclaration6_es6.ts]
//!
//! x 'yield' cannot be used as a parameter within generator
//! ,----
//! ,-[1:1]
//! 1 | function*foo(a = yield) {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,7 +1,8 @@
//// [FunctionDeclaration6_es6.ts]
//!
//! x 'yield' cannot be used as a parameter within generator
//! ,----
//! ,-[1:1]
//! 1 | function*foo(a = yield) {
//! : ^^^^^
//! 2 | }
//! `----
@@ -1,7 +1,11 @@
//// [FunctionDeclaration7_es6.ts]
//!
//! x 'yield' cannot be used as a parameter within generator
//! ,----
//! 3 | function*foo(a = yield) {
//! : ^^^^^
//! ,-[1:1]
//! 1 | function*bar() {
//! 2 | // 'yield' here is an identifier, and not a yield expression.
//! 3 | function*foo(a = yield) {
//! : ^^^^^
//! 4 | }
//! 5 | }
//! `----
@@ -1,7 +1,11 @@
//// [FunctionDeclaration7_es6.ts]
//!
//! x 'yield' cannot be used as a parameter within generator
//! ,----
//! 3 | function*foo(a = yield) {
//! : ^^^^^
//! ,-[1:1]
//! 1 | function*bar() {
//! 2 | // 'yield' here is an identifier, and not a yield expression.
//! 3 | function*foo(a = yield) {
//! : ^^^^^
//! 4 | }
//! 5 | }
//! `----
@@ -1,7 +1,8 @@
//// [VariableDeclaration11_es6.ts]
//!
//! x `let` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | "use strict";
//! 2 | let
//! : ^^^
//! `----
@@ -1,7 +1,8 @@
//// [VariableDeclaration11_es6.ts]
//!
//! x `let` cannot be used as an identifier in strict mode
//! ,----
//! ,-[1:1]
//! 1 | "use strict";
//! 2 | let
//! : ^^^
//! `----
Expand Up @@ -2,7 +2,9 @@
//!
//! x Unexpected token `yield`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp,
//! | ` for template literal, (, or an identifier
//! ,----
//! ,-[1:1]
//! 1 | yield(foo);
//! : ^^^^^
//! 2 | function* foo() {
//! 3 | yield(foo);
//! `----
Expand Up @@ -2,7 +2,9 @@
//!
//! x Unexpected token `yield`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp,
//! | ` for template literal, (, or an identifier
//! ,----
//! ,-[1:1]
//! 1 | yield(foo);
//! : ^^^^^
//! 2 | function* foo() {
//! 3 | yield(foo);
//! `----
@@ -1,7 +1,9 @@
//// [abstractPropertyInitializer.ts]
//!
//! x Abstract property cannot have an initializer.
//! ,----
//! 2 | abstract prop = 1
//! : ^^^^^^^^^^^^^^^^^
//! ,-[1:1]
//! 1 | abstract class C {
//! 2 | abstract prop = 1
//! : ^^^^^^^^^^^^^^^^^
//! 3 | }
//! `----
@@ -1,7 +1,9 @@
//// [abstractPropertyInitializer.ts]
//!
//! x Abstract property cannot have an initializer.
//! ,----
//! 2 | abstract prop = 1
//! : ^^^^^^^^^^^^^^^^^
//! ,-[1:1]
//! 1 | abstract class C {
//! 2 | abstract prop = 1
//! : ^^^^^^^^^^^^^^^^^
//! 3 | }
//! `----
38 changes: 26 additions & 12 deletions crates/swc/tests/tsc-references/accessorWithES3.1.normal.js
@@ -1,25 +1,39 @@
//// [accessorWithES3.ts]
//!
//! x jsc.target should be es5 or upper to use getter / setter
//! ,----
//! 5 | get x() {
//! : ^
//! ,-[3:1]
//! 3 |
//! 4 | class C {
//! 5 | get x() {
//! : ^
//! 6 | return 1;
//! 7 | }
//! `----
//!
//! x jsc.target should be es5 or upper to use getter / setter
//! ,----
//! 11 | set x(v) {
//! : ^
//! ,-[9:1]
//! 9 |
//! 10 | class D {
//! 11 | set x(v) {
//! : ^
//! 12 | }
//! 13 | }
//! `----
//!
//! x jsc.target should be es5 or upper to use getter / setter
//! ,----
//! 16 | get a() { return 1 }
//! : ^
//! ,-[14:1]
//! 14 |
//! 15 | var x = {
//! 16 | get a() { return 1 }
//! : ^
//! 17 | }
//! `----
//!
//! x jsc.target should be es5 or upper to use getter / setter
//! ,----
//! 20 | set b(v) { }
//! : ^
//! ,-[18:1]
//! 18 |
//! 19 | var y = {
//! 20 | set b(v) { }
//! : ^
//! 21 | }
//! `----