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

Modules support #430

Open
wants to merge 148 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
79f1235
Add import/export syntax support to the parser
oleiade Dec 6, 2021
c0a2c6f
fix panics
mstoykov Dec 8, 2021
c086747
fixup! Add import/export syntax support to the parser
oleiade Dec 8, 2021
6c4b34a
WIP ModuleRecords implementation
mstoykov Dec 8, 2021
f58707a
WIP enabling of tests and fixing panics
mstoykov Dec 11, 2021
0d2f247
WIP more "fixes"
mstoykov Dec 11, 2021
56ef325
WIP treat import and export as identifiers in Object Property Key par…
oleiade Dec 15, 2021
6568120
WIP address reserved-words/ident-name-keyword-memberexpr.js test
oleiade Dec 20, 2021
96d718b
finish implementing ParseModule
mstoykov Dec 12, 2021
d181d64
Revert some changes to compileModule
mstoykov Feb 9, 2022
ba73998
Merge remote-tracking branch 'origin/master' into modules
mstoykov Feb 9, 2022
ea0512e
Require import/export to be in the global scope
mstoykov Feb 9, 2022
8fc9a3b
Fix some export as syntax
mstoykov Feb 9, 2022
d0e7456
tc39: run module tests only as strict
mstoykov Feb 9, 2022
6a26d4e
Fix a bunch of parsing and compilation errors
mstoykov Feb 13, 2022
6a96898
Fix hostResolveImportedModule in tc39
mstoykov Feb 14, 2022
4430b25
Fix some early errors
mstoykov Feb 14, 2022
af5be25
wip
mstoykov Apr 4, 2022
85f5577
Add simple failing test
mstoykov May 16, 2022
c1786b3
Basic import/export for let/const/functions works + cleanup
mstoykov Jun 2, 2022
f26423c
Merge remote-tracking branch 'origin/master' into modules
mstoykov Jun 2, 2022
9bafbfb
Implement basic default export/import
mstoykov Jun 3, 2022
28d747c
Disable a bunch of class tests
mstoykov Jun 3, 2022
27ae1e1
Default loop test
mstoykov Jun 3, 2022
c9d3713
WIP refactor
mstoykov Jun 3, 2022
1e617f0
Make possible to Run the same compiled modules in parallel
mstoykov Jun 6, 2022
238dccd
Split ParseModule into ParseModule And ModuleFromAst
mstoykov Jun 6, 2022
26a0311
Fix go vet
mstoykov Jun 6, 2022
2bfb575
Fix some test panics
mstoykov Jun 6, 2022
439b7ec
More vet fixes
mstoykov Jun 6, 2022
258d0cf
fixes for staticcheck
mstoykov Jun 6, 2022
6acaadb
Make compiler when needed for modules
mstoykov Jun 7, 2022
b314f9b
Remove hostResolveImportedModule from runtime
mstoykov Jun 7, 2022
b1eeef4
fix returning ModuleInstance on Evaluation
mstoykov Jun 7, 2022
c1f7626
Fixes for imports in various cases
mstoykov Jun 9, 2022
788e4c0
Use ModuleRecord not Instance when resolving during evaluation
mstoykov Jun 10, 2022
0f987b8
Use ModuleRecord when resolving in compileImportDeclaration
mstoykov Jun 10, 2022
eaf169d
I think I got this wrong from the spec
mstoykov Jun 10, 2022
4e6b825
Support arrow functions (among others) as default export
mstoykov Jun 10, 2022
a73983a
More parsing fies
mstoykov Jun 11, 2022
82cf429
Throw ReferenceError before imports are initialized
mstoykov Jun 14, 2022
04e0b13
Fix trailing commas in import lists
mstoykov Jun 16, 2022
90a123b
Top level function definitions in modules should be lexical
mstoykov Jun 16, 2022
ecbdc4c
Throw syntax errors on exporting unknown bindings
mstoykov Jun 16, 2022
b50623e
Don't require a semicolon after default export of a function
mstoykov Jun 16, 2022
a8d14d0
Report ambigiuous impotts later
mstoykov Jun 16, 2022
f3e29a8
Fix a bunch of ambigious import/export tests
mstoykov Jun 16, 2022
55b2c88
Fix lexical and indirect exports
mstoykov Jun 16, 2022
95d8b1f
Fix parsing errors with semicolons
mstoykov Jun 16, 2022
9c2eeb0
check identifiers on import
mstoykov Jun 16, 2022
9438c84
relay error up when it happens during compilation of module
mstoykov Jun 16, 2022
a0905d8
Report default not being exported during runtime
mstoykov Jun 17, 2022
764969c
Hacks around default exporting function and it being imported
mstoykov Jun 17, 2022
9eee9ed
disable tests with generators
mstoykov Jun 17, 2022
69f3638
Report duplicate import names as syntax error
mstoykov Jun 18, 2022
b4df043
Don't print each Link error
mstoykov Jun 19, 2022
50f5a3c
WIP namespace support
mstoykov Jun 23, 2022
67ce717
Disable one more test as it includes generators
mstoykov Jun 23, 2022
e2a6d0f
fix all namespace tests currently enabled
mstoykov Jun 23, 2022
298427a
Enable more tests and fix this in module code
mstoykov Jun 27, 2022
0d601bf
Fix namespace and default export combo
mstoykov Jun 27, 2022
2a17760
Fix Object.keys for namespace
mstoykov Jun 27, 2022
ffbc556
Fix namespace @toStrinTag
mstoykov Jun 27, 2022
cc0f1fa
Dump exception stack on error in tc39 test
mstoykov Jun 27, 2022
19c9705
Fix getOwnPropertyDesc on namespaces
mstoykov Jun 27, 2022
5df2955
Disable test using generators
mstoykov Jun 27, 2022
ca6a056
Sort Namespace keys to fix 2 tests
mstoykov Jul 4, 2022
a8cca03
Fix a bunch of namespace tc39 tests
mstoykov Jul 6, 2022
ae9681c
Fix Object.hasOwnProperty - fixing two namespace tc39 tests
mstoykov Jul 6, 2022
82e5070
Fix final failing tc39 test and 'fix' Object.freeze
mstoykov Jul 6, 2022
0e64871
Fix parser tests
mstoykov Jul 6, 2022
cb59891
staticcheck fix
mstoykov Jul 6, 2022
c60a76b
Cleaning up module.go
mstoykov Jul 6, 2022
85504f8
Rename module.go to modules.go
mstoykov Jul 6, 2022
3d5ae31
making token/token_const.go diff smaller
mstoykov Jul 6, 2022
7d1c44b
drops some logs from tc39_test.go
mstoykov Jul 6, 2022
7284797
Remove strange code
mstoykov Jul 6, 2022
66b293c
Revet some changes on compiler_expr.go
mstoykov Jul 6, 2022
3df258e
some compiler.go cleanup and TODOs
mstoykov Jul 6, 2022
d267aab
Remove go-spew from the requirements
mstoykov Jul 6, 2022
54cf237
Fix staticcheck
mstoykov Jul 6, 2022
54c482f
Revert some vm.go changes
mstoykov Jul 6, 2022
c8cb78c
refactor ModuleRecord#GetExportedNames
mstoykov Jul 7, 2022
eea69e4
Rework *Module* interfaces and add a bigger not source code module test
mstoykov Jul 12, 2022
dce811c
Bump minimal go to 1.16 for io/fs
mstoykov Jul 21, 2022
dc51713
Merge remote-tracking branch 'origin/master' into modules
mstoykov Jul 21, 2022
f5a9c53
Merge remote-tracking branch 'origin/master' into modules
mstoykov Jul 22, 2022
ecf79f8
Enable tc39 module tests again and add class support
mstoykov Jul 25, 2022
31502c6
Make GetBindingValue simpler
mstoykov Jul 25, 2022
bdf1719
don't panic in GetBindingValue when asked for not existing binding
mstoykov Jul 25, 2022
82f046e
Don't require CyclicModuleRecord in a few places
mstoykov Jul 26, 2022
ec18d21
typo
mstoykov Jul 26, 2022
7af4a69
Merge remote-tracking branch 'origin/master' into modules
mstoykov Jul 27, 2022
22f4a9a
Drop some comments in the parser
mstoykov Jul 28, 2022
abdba61
Fix emptying the stack in the modules inner methods
mstoykov Jul 28, 2022
0ebc65d
Fix import/export indexes
mstoykov Aug 1, 2022
262260d
Some parser comment cleanup
mstoykov Aug 1, 2022
a3b018b
Move modules' namespace in separate file
mstoykov Aug 2, 2022
9c46869
Some modules refactoring
mstoykov Aug 2, 2022
17c7411
Add import.meta support
mstoykov Aug 2, 2022
1917e74
fix parser tests
mstoykov Aug 2, 2022
9fc296e
Merge remote-tracking branch 'origin/master' into modules
mstoykov Aug 2, 2022
822c8e2
Fix usage of exports before the module is evaluated
mstoykov Aug 11, 2022
8164826
dynamic import :tada:
mstoykov Aug 12, 2022
fa51094
Merge remote-tracking branch 'origin/master' into modules
mstoykov Aug 15, 2022
48efda2
fix parser test
mstoykov Aug 15, 2022
135e850
refactor
mstoykov Aug 16, 2022
aab267b
Make dynamic import usable with not source modules
mstoykov Aug 17, 2022
ca4fe85
Don't require the usage of unistring.String from ESM users
mstoykov Aug 17, 2022
e96fa25
Fix race in the simpleComboResolver
mstoykov Aug 17, 2022
99a802c
Move SourceText module in separate file
mstoykov Aug 17, 2022
4c85e02
Add support tla/async evaluation of modules
mstoykov Aug 19, 2022
5f81441
fixup! Add support tla/async evaluation of modules
mstoykov Aug 22, 2022
cbddd50
Merge branch 'master' into modules
mstoykov Sep 7, 2022
a1a2dc5
Revert formatting
mstoykov Sep 7, 2022
ae2a9b9
drop wrong createImmutableBinding
mstoykov Sep 7, 2022
df602e6
Merge remote-tracking branch 'origin/master' into modules
mstoykov Nov 10, 2022
cbaa207
Merge commit 'd4bf6fde1b86bc185110897884ac99981f08a3c6' into modules
mstoykov Mar 29, 2023
164d305
Merge commit '33bff8fdda616056a9eb9b42853e12e9feafc8f9' into modules
mstoykov Mar 29, 2023
5c05a99
fixup! Merge commit '33bff8fdda616056a9eb9b42853e12e9feafc8f9' into m…
mstoykov Mar 29, 2023
f5eb8e6
fixup! Merge commit 'd4bf6fde1b86bc185110897884ac99981f08a3c6' into m…
mstoykov Mar 29, 2023
c42e14e
Merge commit 'bce246427290cf863f71bb8e13feecddfcf7a581' into modules
mstoykov Mar 29, 2023
02a8ab7
Merge commit 'cc4634e76e9a7d2a06f4cb2a2d1ece06946f2f0a' into modules
mstoykov Mar 29, 2023
00a05a6
Merge commit '2e4cbb9852728d28b9ca30b11c057de50686fe76' into modules
mstoykov Mar 29, 2023
c6432ea
Merge commit '78b980256d04d7fc5278cd9839c61ea10884c899' into modules
mstoykov Mar 29, 2023
10e7629
Merge commit '5460598cfa3203e1b803d204ff54f8d7d7323a38' into modules
mstoykov Mar 29, 2023
09c2894
Merge commit '746f7ebdc5149b6af9ac8ba2a0b1fc0ec917cdcc' into modules
mstoykov Mar 29, 2023
fe1020b
Merge commit '5937a312edda9e86e50a49da61ad09fde83063c3' into modules
mstoykov Mar 29, 2023
80527f5
Merge commit 'e2f543bf4b4c03d1f86e5acde716acdfab08304b' into modules
mstoykov Mar 29, 2023
80ec257
Merge remote-tracking branch 'origin/master' into modules
mstoykov Jun 7, 2023
1fbb864
Merge remote-tracking branch 'origin/master' into modules
mstoykov Aug 15, 2023
7986602
Use AsyncFunc to implement modules getting rid of old hack
mstoykov Sep 12, 2023
e2e7f14
Merge remote-tracking branch 'origin/master' into modules
mstoykov Sep 28, 2023
ec99aff
Remove dead code
mstoykov Sep 28, 2023
530c106
TLA Support
mstoykov Oct 3, 2023
2507228
Fix go vet
mstoykov Oct 5, 2023
789cda2
Fix staticcheck and some cleanup
mstoykov Oct 5, 2023
a059c52
Fix old parser test :facepalm:
mstoykov Oct 6, 2023
bf5368f
more staticcheck fixes
mstoykov Oct 6, 2023
97ea475
Merge remote-tracking branch 'origin/master' into modules
mstoykov Oct 26, 2023
a0920e6
Refactor modules_test.go to be more easy to work with
mstoykov Oct 26, 2023
1b8ab0d
Support 'eval' with imported identifiers
mstoykov Nov 8, 2023
2ecad8a
Fix errors and exceptions around modules and imports
mstoykov Nov 13, 2023
5bcf414
small fix
mstoykov Nov 14, 2023
7aaf816
Make certains SourceModules InitalizeEnvironement
mstoykov Nov 15, 2023
178b2c3
Reduce diff size
mstoykov Nov 16, 2023
08f562e
small fixes
mstoykov Dec 12, 2023
c733ab4
Merge remote-tracking branch 'origin/master' into modules
mstoykov Jun 7, 2024
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
94 changes: 93 additions & 1 deletion ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ type (
SuperExpression struct {
Idx file.Idx
}
DynamicImportExpression struct {
Idx file.Idx
}

UnaryExpression struct {
Operator token.Token
Expand Down Expand Up @@ -336,6 +339,8 @@ func (*ObjectPattern) _expressionNode() {}
func (*ArrayPattern) _expressionNode() {}
func (*Binding) _expressionNode() {}

func (*DynamicImportExpression) _expressionNode() {}

func (*PropertyShort) _expressionNode() {}
func (*PropertyKeyed) _expressionNode() {}

Expand Down Expand Up @@ -482,7 +487,71 @@ type (
}

FunctionDeclaration struct {
Function *FunctionLiteral
Function *FunctionLiteral
IsDefault bool // TODO figure out how to not have to that
}

ImportDeclaration struct {
Idx file.Idx
ImportClause *ImportClause
FromClause *FromClause
ModuleSpecifier unistring.String
}

ImportClause struct {
ImportedDefaultBinding *Identifier
NameSpaceImport *NameSpaceImport
NamedImports *NamedImports
}

NameSpaceImport struct {
ImportedBinding unistring.String
}

NamedImports struct {
ImportsList []*ImportSpecifier
}

ImportSpecifier struct {
IdentifierName unistring.String
Alias unistring.String
}

ExportDeclaration struct {
Idx file.Idx
Variable *VariableStatement
AssignExpression Expression
LexicalDeclaration *LexicalDeclaration
ClassDeclaration *ClassDeclaration
NamedExports *NamedExports
ExportFromClause *ExportFromClause
FromClause *FromClause
HoistableDeclaration *HoistableDeclaration
IsDefault bool
}

FromClause struct {
ModuleSpecifier unistring.String
}
ExportFromClause struct {
IsWildcard bool
Alias unistring.String
NamedExports *NamedExports
}

NamedExports struct {
ExportsList []*ExportSpecifier
}

ExportSpecifier struct {
IdentifierName unistring.String
Alias unistring.String
}

HoistableDeclaration struct {
FunctionDeclaration *FunctionDeclaration
// GeneratorDeclaration
// AsyncFunc and AsyncGenerator
}

ClassDeclaration struct {
Expand Down Expand Up @@ -517,6 +586,9 @@ func (*LexicalDeclaration) _statementNode() {}
func (*FunctionDeclaration) _statementNode() {}
func (*ClassDeclaration) _statementNode() {}

func (*ExportDeclaration) _statementNode() {}
func (*ImportDeclaration) _statementNode() {}

// =========== //
// Declaration //
// =========== //
Expand Down Expand Up @@ -633,6 +705,10 @@ type Program struct {
Body []Statement

DeclarationList []*VariableDeclaration
ImportEntries []*ImportDeclaration
ExportEntries []*ExportDeclaration

HasTLA bool

File *file.File
}
Expand Down Expand Up @@ -679,6 +755,8 @@ func (self *UnaryExpression) Idx0() file.Idx {
}
func (self *MetaProperty) Idx0() file.Idx { return self.Idx }

func (self *DynamicImportExpression) Idx0() file.Idx { return self.Idx }

func (self *BadStatement) Idx0() file.Idx { return self.From }
func (self *BlockStatement) Idx0() file.Idx { return self.LeftBrace }
func (self *BranchStatement) Idx0() file.Idx { return self.Idx }
Expand Down Expand Up @@ -713,6 +791,9 @@ func (self *PropertyShort) Idx0() file.Idx { return self.Name.Id
func (self *PropertyKeyed) Idx0() file.Idx { return self.Key.Idx0() }
func (self *ExpressionBody) Idx0() file.Idx { return self.Expression.Idx0() }

func (self *ExportDeclaration) Idx0() file.Idx { return self.Idx }
func (self *ImportDeclaration) Idx0() file.Idx { return self.Idx }

func (self *VariableDeclaration) Idx0() file.Idx { return self.Var }
func (self *FieldDefinition) Idx0() file.Idx { return self.Idx }
func (self *MethodDefinition) Idx0() file.Idx { return self.Idx }
Expand Down Expand Up @@ -767,10 +848,13 @@ func (self *UnaryExpression) Idx1() file.Idx {
}
return self.Operand.Idx1()
}

func (self *MetaProperty) Idx1() file.Idx {
return self.Property.Idx1()
}

func (self *DynamicImportExpression) Idx1() file.Idx { return self.Idx + 6 }

func (self *BadStatement) Idx1() file.Idx { return self.To }
func (self *BlockStatement) Idx1() file.Idx { return self.RightBrace + 1 }
func (self *BranchStatement) Idx1() file.Idx {
Expand Down Expand Up @@ -841,6 +925,14 @@ func (self *PropertyKeyed) Idx1() file.Idx { return self.Value.Idx1() }

func (self *ExpressionBody) Idx1() file.Idx { return self.Expression.Idx1() }

func (self *ExportDeclaration) Idx1() file.Idx {
return self.Idx + file.Idx(len(token.EXPORT.String()))
}

func (self *ImportDeclaration) Idx1() file.Idx {
return self.Idx + file.Idx(len(token.IMPORT.String()))
}

func (self *VariableDeclaration) Idx1() file.Idx {
if len(self.List) > 0 {
return self.List[len(self.List)-1].Idx1()
Expand Down
23 changes: 8 additions & 15 deletions builtin_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,16 @@ func (r *Runtime) object_freeze(call FunctionCall) Value {
obj.self.preventExtensions(true)

for item, next := obj.self.iterateKeys()(); next != nil; item, next = next() {
if prop, ok := item.value.(*valueProperty); ok {
prop.configurable = false
if !prop.accessor {
prop.writable = false
}
prop := obj.getOwnProp(item.name)
descr := PropertyDescriptor{
Configurable: FLAG_FALSE,
}
if prop, ok := prop.(*valueProperty); ok && prop.accessor {
// no-op
} else {
prop := obj.getOwnProp(item.name)
descr := PropertyDescriptor{
Configurable: FLAG_FALSE,
}
if prop, ok := prop.(*valueProperty); ok && prop.accessor {
// no-op
} else {
descr.Writable = FLAG_FALSE
}
obj.defineOwnProperty(item.name, descr, true)
descr.Writable = FLAG_FALSE
}
obj.defineOwnProperty(item.name, descr, true)
Comment on lines 286 to +296
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just what the specification says - I think the previous code was making it faster in some cases but I couldn't figure out how to fix it in any other way 🤷‍♂and had other problems ;)

This is problematic for the way I have implemented modules namespace, which might be the actual problem 🤷‍♂ but this was in reality one of the places where it had problems and both were fixed by doing exactly what the specification says.

}
return obj
} else {
Expand Down
Loading
Loading