AssemblyScript/assemblyscript

Changing source file extension

bobbinth opened this issue · 8 comments

Is it possible to change file extension for AssemblyScript source files to something other than .ts (e.g. .as)?

I tried doing something like:

asc assembly/index.as -b build/optimized.wasm

But getting the following error:

Entry file 'assembly/index.as.ts' not found.

The .ts extension is the only one recognized currently, but if there's a need for another one, from an AssemblyScript perspective I'd say "why not". Note, though, that adding alternative file extensions to TypeScript (if you'd like to utilize it for example with VSCode for syntax highlighting) appeared to be pretty much impossible without forking it the last time I checked.

I think you can make it kind of work in VS Code:

First, set file association settings like so:

"files.associations": {
  "*.as": "typescript"
}

Then instead of relying on tsconfig.json file, use /// directives at the top of .as files like so:

/// <reference path="../../node_modules/assemblyscript/std/assembly/index.d.ts" />

Iirc correctly it used to be more complicated than that, perhaps because import statements didn't pick up files with alternative extensions and similar things. If it's somehow possible, though, feel free to investigate further :)

For a bit of additional background: My stance on this so far was to delay this until there's a dedicated language service for AssemblyScript, which in turn is likely to allow picking whatever file extension(s) we'd like.

Yeah, import statements don't seem to work for .as extensions. Though, they do work for .tsx extensions.

btw, the reason for the question in the first place is that I'm trying to create a project that has both AS and TS files, and I'm trying to figure out what's the best way to clearly separate them.

What I've been doing so far is to have two source directories, both with their own tsconfig.json. For example assembly/ for AS and src/ for TS.

I do the same - but I wanted to have a single TS file with loader code etc. per module. The way I decided to do this is by using .as.ts as file extension for my AS files and then telling TS compiler to ignore any files that end with .as.ts. So, my directory structure looks something like this:

.
├── assembly
|   ├── fooModule
|   |   ├── index.ts
|   |   ├── foo1.as.ts
|   |   └── foo2.as.ts
|   └── barModule
|   |   ├── index.ts
|   |   ├── bar1.as.ts
|   |   └── bar2.as.ts
|   └── index.ts

I'm closing this issue since I don't need it any more, and this is probably better addresses as a part of a bigger issue (e.g. #390).

@dcodeIO Bump! Can we create support for optional extensions for full file names?

I follow the discussion around the extension now a bit longer and I want to suggest a total rebrand from AssemblyScript to binode.