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

fix(ts-wrappers): fix TypeScript wrappers generation for messages with single quote #1106

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `as coins` map value serialization type is now handled correctly: PR [#987](https://github.com/tact-lang/tact/pull/987)
- Type checking for `foreach` loops in trait methods: PR [#1017](https://github.com/tact-lang/tact/pull/1017)
- The `sha256()` function no longer throws on statically known strings of any length: PR [#907](https://github.com/tact-lang/tact/pull/907)
- TypeScript wrappers generation for messages with single quote: PR [#1106](https://github.com/tact-lang/tact/pull/1106)

### Release contributors

Expand Down
14 changes: 11 additions & 3 deletions src/bindings/writeTypescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,12 @@ export function writeTypescript(
r.message.text !== null &&
r.message.text !== undefined
) {
receivers.push(`'${r.message.text}'`);
// since we are using single quotes, escape them in the message name
const escaped = r.message.text.replace(
i582 marked this conversation as resolved.
Show resolved Hide resolved
/'/g,
"\\'",
);
receivers.push(`'${escaped}'`);
} else {
receivers.push(`string`);
}
Expand Down Expand Up @@ -419,9 +424,12 @@ export function writeTypescript(
});
w.append(`}`);
} else {
w.append(
`if (message === '${msg.text}') {`,
// since we are using single quotes, escape them in the message name
const escaped = msg.text.replace(
/'/g,
"\\'",
);
w.append(`if (message === '${escaped}') {`);
w.inIndent(() => {
w.append(
`body = beginCell().storeUint(0, 32).storeStringTail(message).endCell();`,
Expand Down
Loading