near / near-sdk-as

Tools for building NEAR smart contracts in AssemblyScript
https://near.github.io/near-sdk-as/
Other
115 stars 44 forks source link

[Bounty] Add String Interpolation to AssemblyScript #201

Closed willemneal closed 3 years ago

willemneal commented 4 years ago

NEAR Bounty Terms

Before beginning work on the bounty, you must submit a proposal. Only if your proposal is accepted will you be able to claim the reward of the bounty.

Background

A key feature in AssemblyScript that many developers expect is string interpolation, or a string with special variables that are inlined.

For example,

let world = "world";
let str = `Hello ${world}`

Work on this has located in the following PR: https://github.com/AssemblyScript/assemblyscript/pull/1115

You will make a new PR against this PR. This way we can approve it.

As github points out at the bottom of the PR, there are merge conflicts with the current master branch. Thus the first step is to merge with master.

API

As mentioned here, there needs to be new AST node added for template strings:

Adding the following to src/ast.ts

/** Represents a string literal expression. */
export class TemplateLiteralExpression extends LiteralExpression {
  constructor(
    /** String value without quotes. */
    public expresssionParts: Expression[],
    /** Source range. */
    range: Range
  ) {
    super(LiteralKind.TEMPLATE, range);
  }
}

Then update the following in the src/parser.ts to return the new TemplateLiteralExpression.

Update the following method in the Node class in src/ast.ts


static createTemplateLiteralExpression(
    value: string,
    range: Range
  ): StringLiteralExpression {
    return new TemplateLiteralExpression(parts, range);
  }

And the following to src/compiler.ts

compileTemplateLiteral(expr: TemplateLiteralExpression, constraints: Constraints): ExpressionRef {
    const innerExpressions: ExpressionRef[] = expr.expressionParts;
    ....

  }

As also mentioned in the PR, expr.toString() should be compiled for each part and then each must be concatenated.

Testing

Add to tests already present in the PR to test more edge cases.

Proposal

Briefly describe how you would design complieTemplateLiteral and some edge test cases you would add.

developerfred commented 4 years ago

@willemneal Can I also work on this issue?

willemneal commented 4 years ago

It hasn't been posted to gitcoin yet, but you'll get notified here when it is.

gitcoinbot commented 4 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 266 years, 3 months from now. Please review their action plans below:

1) developerfred has been approved to start work.

I'm already getting used to typescript and the Near protocol, I would love to do this feature in AssemblyScript.

Learn more on the Gitcoin Issue Details page.

willemneal commented 4 years ago

@developerfred Sounds good, but for the fairness of the bounty (and I did edit this so I understand if you missed it):

Briefly describe how you would design complieTemplateLiteral and some edge test cases you would add.

developerfred commented 4 years ago

Sounds good, but for the fairness of the bounty (and I did edit this so I understand if you missed it):

thanks for letting me know, i wait to be approved or do i keep working?

willemneal commented 4 years ago

I'm saying you need to do it be approved. Since it's not first come first served we need a way to make it transparent who was awarded and it just shows us that you have an idea of what you'll be doing. It doesn't have to be more than a couple of sentences.

developerfred commented 4 years ago

@willemneal Ah ok! Come on, I will work on the PR: AssemblyScript/assemblyscript#1115 which is already well advanced in its construction, I will follow the literal template pattern ES2015 However, I thought of storing the concatenation in memory in the i32 format, in order not to have a lot of compilation costs and to display converted.

In the first version I will add this specification https://tc39.es/ecma262/#sec-template-literals but I can also add the tags https://tc39.es/ecma262/#sec-tagged-templates

I will write compileTemplateLiteral in a way that does not affect the performance, I will write the tests according to the specifications and also test the @pulpdrew previous work https://github.com/AssemblyScript/assemblyscript/pull/1427#issuecomment-669603917

willemneal commented 4 years ago

Thanks! Sounds great! I'm sorry for the formalities, I'm still new at bounties and want to prevent people starting work before being accepted.

I'm excited to see your progress!

gitcoinbot commented 4 years ago

@developerfred Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

gitcoinbot commented 4 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


@developerfred due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

developerfred commented 4 years ago

@gitcoinbot I'm working on it this week, I'll send the work in progress from the aassemblyscript repo to gitcoin

developerfred commented 4 years ago

@willemneal I submitted the work in progress and I continue working on the bounty.

willemneal commented 4 years ago

@developerfred Any updates?

MaxGraey commented 3 years ago

String interpolations already implemented