How can I tell typescript to include a line verbatim in js without parsing it
Asked Answered
S

2

6

I’m writing an app in typescript to compile to adobe extendscript (an es3-based javascript syntax).

I am trying to use the extendscript-only syntax

#include "path_to_file";

which is not valid typescript (and not even valid javascript). I would like to tell typescript to just include it as-is, without parsing it.

I know about @ts-ignore, and @ts-except-error, but though these prevent typescript from throwing an error, they don’t prevent it from messing the line while transpiling it. In the end the output line is :

#include;

which kinds of defeats the purpose.

Is it possible to tell typescript not to parse next line and to just include it as-is in javascript code ?

(otherwise I’m going to have to resort to some dark Makefile / cat magic)

Stipe answered 30/7, 2020 at 15:42 Comment(0)
R
3

You can achieve what you're looking for by using the alternative extendscript-directive syntax that uses //@ instead of #. The fact it's effectively a comment means typescript will ignore it, but extendscript still sees it.

So change your:

#include "path_to_file";

to be:

//@include "path_to_file";
Relax answered 15/5, 2021 at 20:48 Comment(2)
Thank you ! Though it doesn't really answer the question (how to include a line verbatim), it does solve my problem, so I'll accept your answer. For the record, iirc I had it solved by using this github.com/yellcorp/extendscript-commonjs , and telling typescript to transpile imports to commonjs, so I could just use the native typescript import syntaxStipe
(and the toplevel include of extendscript-commonjs was done in a pure jsx file)Stipe
B
0

Solves the problem without answering the question

const root = File($.fileName).parent
const file = new File(`${root}/../polyFill/index.jsx`);
$.evalFile(file);
Bernadette answered 17/2, 2023 at 2:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.