Fix scale and settlement_as_close namespaces not resolving in scripts - #305
Merged
Merged
Conversation
The `scale` and `settlement_as_close` enums exist in namespaces/Types.ts and
are spread into the context, but were missing from CONTEXT_PINE_VARS, so the
transpiler never bound them and any `scale.*` reference threw
"scale is not defined" (e.g. `indicator("x", scale = scale.right)`).
Also add both to NAMESPACE_COLLISION_NAMES: scripts commonly declare a
variable named `scale` next to `indicator(scale = scale.left)`, which
TradingView allows.
Found in 12 of 729 popular open-source TradingView indicators.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
scaleandsettlement_as_closeare defined insrc/namespaces/Types.ts, spread into the context, and listed as supported indocs/api-coverage/types.md. They are missing fromCONTEXT_PINE_VARS, though, so the transpiler never binds them. Any script that uses them fails:→
ReferenceError: scale is not definedThis script compiles on TradingView. I ran 729 popular open-source indicators from TradingView through PineTS, and 12 of them failed on this.
Fix
scaleandsettlement_as_closetoCONTEXT_PINE_VARS.NAMESPACE_COLLISION_NAMES. Scripts often declare their ownscalevariable next toindicator(scale = scale.left), which TradingView allows.Tests
tests/namespaces/constants.test.ts: the values ofscale.*andsettlement_as_close.*.tests/transpiler/namespace-identifier-collision.test.ts:indicator(scale = scale.none)withoverlay = true, and a user variable namedscale. Both scripts compile on TradingView.dev(scale is not defined) and pass with this change. Full suite: 1842 passed, 5 skipped, 16 todo.devand once against this branch. 8 now run without errors. 4 get pastscaleand then stop at other unsupported features. The other scripts show no regressions and no changed output values. 8 scripts give different output on two identicaldevruns, so I left them out of the value comparison.The repro scripts and tooling are in https://github.com/lenstrats/pinets-compat.
🤖 Generated with Claude Code