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

GSoC'21: adding to FES phase 1 #5305

Merged
merged 20 commits into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/core/friendly_errors/browser_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ const strings = {
msg: "Can't find variable: {{}}",
type: 'NOTDEFINED',
browser: 'Safari'
},
{
msg: "Cannot access '{{.}}' before initialization",
type: 'CANNOTACCESS',
browser: 'Chrome'
},
{
msg: "can't access lexical declaration '{{.}}' before initialization",
type: 'CANNOTACCESS',
browser: 'Firefox'
}
],
SyntaxError: [
Expand Down Expand Up @@ -42,13 +52,73 @@ const strings = {
msg: "expected {{.}}, got '{{.}}'",
type: 'UNEXPECTEDTOKEN',
browser: 'Chrome'
},
{
msg: "Identifier '{{.}}' has already been declared",
type: 'REDECLAREDVARIABLE',
browser: 'Chrome'
},
{
msg: 'redeclaration of {} {{.}}',
type: 'REDECLAREDVARIABLE',
browser: 'Firefox'
},
{
msg: 'Missing initializer in const declaration',
type: 'MISSINGINITIALIZER',
browser: 'Chrome'
},
{
msg: 'missing = in const declaration',
type: 'MISSINGINITIALIZER',
browser: 'Firefox'
},
{
msg: 'Illegal return statement',
type: 'BADRETURNORYIELD',
browser: 'Chrome'
},
{
msg: 'return not in function',
type: 'BADRETURNORYIELD',
browser: 'Firefox'
lm-n marked this conversation as resolved.
Show resolved Hide resolved
}
],
TypeError: [
{
msg: '{{.}} is not a function',
type: 'NOTFUNC',
browser: 'all'
},
{
msg: "Cannot read property '{{.}}' of null",
type: 'READNULL',
browser: 'Chrome'
},
{
msg: '{{.}} is null',
type: 'READNULL',
browser: 'Firefox'
},
{
msg: "Cannot read property '{{.}}' of undefined",
type: 'READUDEFINED',
browser: 'Chrome'
},
{
msg: '{{.}} is undefined',
type: 'READUDEFINED',
browser: 'Firefox'
},
{
msg: 'Assignment to constant variable',
type: 'CONSTASSIGN',
browser: 'Chrome'
},
{
msg: "invalid assignment to const '{{.}}'",
type: 'CONSTASSIGN',
browser: 'Firefox'
}
]
};
Expand Down
104 changes: 104 additions & 0 deletions src/core/friendly_errors/fes_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,38 @@ if (typeof IS_MINIFIED !== 'undefined') {
);
break;
}
case 'REDECLAREDVARIABLE': {
let errSym = matchedError.match[1];
let url =
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Redeclared_parameter#what_went_wrong';
p5._friendlyError(
translator('fes.globalErrors.syntax.redeclaredVariable', {
symbol: errSym,
url
})
);
break;
}
case 'MISSINGINITIALIZER': {
let url =
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_initializer_in_const#what_went_wrong';
p5._friendlyError(
translator('fes.globalErrors.syntax.missingInitializer', {
url
})
);
break;
}
case 'BADRETURNORYIELD': {
let url =
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Bad_return_or_yield#what_went_wrong';
p5._friendlyError(
translator('fes.globalErrors.syntax.badReturnOrYield', {
url
})
);
break;
}
lm-n marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}
Expand Down Expand Up @@ -759,6 +791,23 @@ if (typeof IS_MINIFIED !== 'undefined') {
})
);

if (friendlyStack) printFriendlyStack(friendlyStack);
break;
}
case 'CANNOTACCESS': {
let errSym = matchedError.match[1];
let url =
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_lexical_declaration_before_init#what_went_wrong';
p5._friendlyError(
translator('fes.globalErrors.reference.cannotAccess', {
url,
symbol: errSym,
location: locationObj
? translator('fes.location', locationObj)
: ''
})
);

if (friendlyStack) printFriendlyStack(friendlyStack);
break;
}
Expand Down Expand Up @@ -797,6 +846,61 @@ if (typeof IS_MINIFIED !== 'undefined') {
);
}

if (friendlyStack) printFriendlyStack(friendlyStack);
break;
}
case 'READNULL': {
let errSym = matchedError.match[1];
let url1 =
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_property#what_went_wrong';
let url2 =
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null';
p5._friendlyError(
translator('fes.globalErrors.type.readFromNull', {
url1,
url2,
symbol: errSym,
location: locationObj
? translator('fes.location', locationObj)
: ''
})
);

if (friendlyStack) printFriendlyStack(friendlyStack);
break;
}
case 'READUDEFINED': {
let errSym = matchedError.match[1];
let url1 =
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_property#what_went_wrong';
let url2 =
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined#description';
p5._friendlyError(
translator('fes.globalErrors.type.readFromUndefined', {
url1,
url2,
symbol: errSym,
location: locationObj
? translator('fes.location', locationObj)
: ''
})
);

if (friendlyStack) printFriendlyStack(friendlyStack);
break;
}
case 'CONSTASSIGN': {
let url =
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_const_assignment#what_went_wrong';
p5._friendlyError(
translator('fes.globalErrors.type.constAssign', {
url,
location: locationObj
? translator('fes.location', locationObj)
: ''
})
);

if (friendlyStack) printFriendlyStack(friendlyStack);
break;
}
Expand Down
Loading