Skip to content

Parser identifies ~lib/rt/index-full as SourceKind.USER_ENTRY #889

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

Closed
sampaioletti opened this issue Oct 8, 2019 · 5 comments
Closed

Parser identifies ~lib/rt/index-full as SourceKind.USER_ENTRY #889

sampaioletti opened this issue Oct 8, 2019 · 5 comments
Labels

Comments

@sampaioletti
Copy link

While playing with the transform option I noticed the ~lib/rt/index-full source is recognized as SourceKind.USER_ENTRY as is my user generated entry file, I would have thought it would be SourceKind.LIBRARY

If that is the intended classification how would one determine the difference between a user file in this scenario

It is classified as such due to the following

//taken from src/parser.ts:140
//path= ~lib/rt/index-full
path.indexOf(PATH_DELIMITER, LIBRARY_PREFIX.length) < 0 
//results in 7<0=false

var source = new Source(
normalizedPath,
text,
isEntry
? SourceKind.USER_ENTRY
: path.startsWith(LIBRARY_PREFIX)
? path.indexOf(PATH_DELIMITER, LIBRARY_PREFIX.length) < 0
? SourceKind.LIBRARY_ENTRY
: SourceKind.LIBRARY
: SourceKind.USER
);

@dcodeIO
Copy link
Member

dcodeIO commented Oct 8, 2019

This is intended behavior. One can think of this as linking two programs together on source level, based on two entries. What the compiler does there is to parse the runtime entry before the user entry where both can have their own module-level exports (which LIBRARY files can't have / LIBRARY_ENTRY marks a file where exports become globals, not module exports). Perhaps just ENTRY (for any explicit entry file) would be a better name to avoid confusion? And rename LIBRARY_ENTRY to LIBRARY_ROOT?

@sampaioletti
Copy link
Author

ah...that does make sense, I assumed (in the context of trying to develop a transform) that was how i could find the users entry file. I had been folloiwng along with

https://github.com/holochain/hdk-assemblyscript/blob/7fd3f11e8180b3c9ce08a05c5cf32fff624c527a/transforms/zome_function.js#L26

and assumed this was the correct way to replace that call in the current api

The renames make sense to me, but I can close if its a non-issue since this is intended behavior

@willemneal
Copy link
Contributor

@sampaioletti You should try out my PR: #866, it's in typescript, but it makes transforming much easier. Here's an example of using the transformer class for the binding code to Near Protocol's bindings. It informed informed the PR when trying to create a proper tooling setup for working externally on creating transformers.

@dcodeIO I vote for adding another case. I too had this issue when filter for user entry files how about RUNTIME_ENTRY or STARTUP_ENTRY?

@sampaioletti
Copy link
Author

@willemneal That looks real cool I'll pull it down and give it a try, I think its great that its in TS...i'm not a a js guy so I only do it when i have to (:

I did manage to make a transform that did what i wanted to for my example at
https://github.com/sampaioletti/assemblyscript/tree/rem-allocate/examples/rem-allocate

but i can see the advantages of using your class thanks for the info!

@stale
Copy link

stale bot commented Nov 9, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 9, 2019
@stale stale bot closed this as completed Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants