Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jsexplain
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verified Software
jsexplain
Commits
023c5230
Commit
023c5230
authored
9 years ago
by
Thomas Wood
Browse files
Options
Downloads
Patches
Plain Diff
Add tuple type checking
parent
24e96186
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/parser.js
+14
-4
14 additions, 4 deletions
test/parser.js
with
14 additions
and
4 deletions
test/parser.js
+
14
−
4
View file @
023c5230
...
...
@@ -148,6 +148,12 @@ function typecheckAST(ast) {
return
type
;
}
// Test for tuple types
if
(
type
.
endsWith
(
'
)
'
))
{
type
=
type
.
substring
(
1
,
type
.
length
-
1
);
return
type
.
split
(
'
*
'
).
map
(
s
=>
s
.
trim
());
}
// Test for poly type
var
i
=
type
.
lastIndexOf
(
'
'
);
if
(
i
>=
0
)
{
...
...
@@ -170,14 +176,13 @@ function typecheckAST(ast) {
}
};
var
errorMsg
=
function
(
value
,
msg
)
{
return
_
=>
esprimaToAST
.
toString
(
value
,
1
)
+
"
"
+
msg
;
};
var
typecheck
=
function
(
type
,
value
)
{
var
t
=
getType
(
type
);
if
(
isBaseType
(
t
))
{
assert
(
t
===
typeof
value
,
errorMsg
(
value
,
"
was expected to have type of
"
+
t
));
}
else
if
(
t
instanceof
Array
)
{
assert
.
instanceOf
(
value
,
Array
);
t
.
forEach
((
type
,
index
)
=>
typecheck
(
type
,
value
[
index
]));
}
else
{
assert
(
value
.
hasOwnProperty
(
"
type
"
),
errorMsg
(
value
,
"
doesn't have a type property
"
));
assert
.
strictEqual
(
t
.
_typeName
,
value
.
type
);
...
...
@@ -194,6 +199,10 @@ function typecheckAST(ast) {
}
};
var
errorMsg
=
function
(
value
,
msg
)
{
return
_
=>
esprimaToAST
.
toString
(
value
,
3
)
+
"
"
+
msg
;
};
return
typecheck
(
"
prog
"
,
ast
);
}
...
...
@@ -241,6 +250,7 @@ walk(test262path)
}
catch
(
e
)
{
if
(
e
instanceof
esprimaToAST
.
UnsupportedSyntaxError
)
{
}
else
{
console
.
log
(
JSON
.
stringify
(
ast
,
null
,
2
));
throw
e
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment