Skip to content

Conversation

@yjhmelody
Copy link
Contributor

@yjhmelody yjhmelody commented Jul 21, 2021

Now export * from "xx" will be built to export {} from "xx".

@willemneal visitor-as also has this problem.

It makes the behavior of the compiler plug-in difficult to understand, because there may be many files that are modified.

@yjhmelody
Copy link
Contributor Author

@willemneal Can you take a look?

@willemneal
Copy link
Contributor

I'm still unsure what the issue is here. Is it that an AST from export * from "" when turned back into a string became export {} from "" and now it will stay the same?

@yjhmelody
Copy link
Contributor Author

yjhmelody commented Jul 27, 2021

I'm still unsure what the issue is here. Is it that an AST from export * from "" when turned back into a string became export {} from "" and now it will stay the same?

Yes, ASTbuilder does not handle the situation when the members of ExportStatement are null.

In program.ts We can see that when members is null, it means the ‘*' syntax.

  /** Initializes an `export` statement. */
  private initializeExports(
    /** The statement to initialize. */
    statement: ExportStatement,
    /** Parent file. */
    parent: File,
    /** So far queued `export`s. */
    queuedExports: Map<File,Map<string,QueuedExport>>,
    /** So far queued `export *`s. */
    queuedExportsStar: Map<File,QueuedExportStar[]>
  ): void {
    var members = statement.members;
    if (members) { // export { foo, bar } [from "./baz"]
      for (let i = 0, k = members.length; i < k; ++i) {
        this.initializeExport(members[i], parent, statement.internalPath, queuedExports);
      }
    } else { // export * from "./baz"
      let queued: QueuedExportStar[];
      if (queuedExportsStar.has(parent)) queued = assert(queuedExportsStar.get(parent));
      else queuedExportsStar.set(parent, queued = []);
      let foreignPath = statement.internalPath!; // must be set for export *
      queued.push(new QueuedExportStar(
        foreignPath,
        foreignPath.endsWith(INDEX_SUFFIX) // strip or add index depending on what's already present
          ? foreignPath.substring(0, foreignPath.length - INDEX_SUFFIX.length)
          : foreignPath + INDEX_SUFFIX,
        assert(statement.path)
      ));
    }
  }

Copy link
Contributor

@willemneal willemneal left a comment

Choose a reason for hiding this comment

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

Okay makes sense to me.

@yjhmelody yjhmelody changed the title fix(astBuilder): fix export fix(astBuilder): fix export statment Jul 29, 2021
@yjhmelody
Copy link
Contributor Author

@MaxGraey Hi, anything wrong ?

@MaxGraey MaxGraey merged commit b7a3db8 into AssemblyScript:main Aug 2, 2021
@yjhmelody yjhmelody deleted the fix-ast-builder branch August 3, 2021 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants