__pragma__('js') bug?

Open
#766 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, python
Domain
compilers

Research direction

Start by reproducing issue #766 with the two pragma('js') import examples, then trace the compiler's import-resolution step after the JavaScript file is generated. Compare the module-name handling for five- and six-character names, and verify that both examples compile without looking for a truncated Python or JavaScript filename.

Written by the indexing model from the issue text.

Description

In trying to use an ES6 style JavaScript import rather than the Node require() function, the js pragma fails if the import module name is more than 5 characters long.

So this transpiles as expected:

__pragma__('js','''import * as test from 'abcde';''')

But this fails:

__pragma__('js','''import * as test from 'abcdef';''')

giving this error:

Error while compiling (offending file last):
        File 'scratch_3', line 0, namely:
        
        Import error, can't find any of:
                /home/jennasys/.config/JetBrains/PyCharm2020.3/scratches/c.py
                /home/jennasys/.config/JetBrains/PyCharm2020.3/scratches/c.js
                /home/data/Python/Transcrypt/pymui/venv/lib/python3.7/site-packages/transcrypt/modules/c.py
                /home/data/Python/Transcrypt/pymui/venv/lib/python3.7/site-packages/transcrypt/modules/c.js
                /home/data/Python/Transcrypt/pymui/venv/bin/c.py
                /home/data/Python/Transcrypt/pymui/venv/bin/c.js
                /usr/lib/python3.7/c.py
                /usr/lib/python3.7/c.js
                /usr/lib/python3.7/lib-dynload/c.py
                /usr/lib/python3.7/lib-dynload/c.js
                /home/data/Python/Transcrypt/pymui/venv/lib/python3.7/site-packages/c.py
                /home/data/Python/Transcrypt/pymui/venv/lib/python3.7/site-packages/c.js
                /home/data/Python/Transcrypt/pymui/venv/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg/c.py
                /home/data/Python/Transcrypt/pymui/venv/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg/c.js
                /home/data/Python/Transcrypt/pymui/venv/lib/python3.7/site-packages/pip-19.0.3-py3.7.egg/c.py
                /home/data/Python/Transcrypt/pymui/venv/lib/python3.7/site-packages/pip-19.0.3-py3.7.egg/c.js


Aborted

In the error, the "filename" it looks for is the name of the import module with the first 2 and last 3 characters removed. So similar to the above example, this:

__pragma__('js','''import * as test from 'abcdefghijk';''')

gives an error of:

Error while compiling (offending file last):
        File 'scratch_3', line 0, namely:
        
        Import error, can't find any of:
                /home/jennasys/.config/JetBrains/PyCharm2020.3/scratches/cdefgh.py
                /home/jennasys/.config/JetBrains/PyCharm2020.3/scratches/cdefgh.js

...

Update: It looks like the JavaScript file containing the ES6 import is actually being generated correctly and the compile error occurs at some point after that happens.

Dominant language
Python
Stars
2.9k
Forks
218
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TranscryptOrg/Transcrypt

All issues in TranscryptOrg/Transcrypt

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.