rokucommunity / brightscript-language

This project is no longer maintained. Its successor is BrighterScript.
https://github.com/RokuCommunity/brighterscript
MIT License
6 stars 3 forks source link

Can we export more things please? #12

Open georgejecook opened 5 years ago

georgejecook commented 5 years ago

I'd like to use brightscript-language in other preprocessor projects, and I assume other's would too.

Currently, not all the classes are exported, which limits extensibility as an npm package.

TwitchBronBron commented 5 years ago

Rather than just blindly exporting classes, I would rather have a discussion about what specifically you are trying to accomplish and how we can best accomplish it.

TwitchBronBron commented 5 years ago

Most of the inner classes don't make sense to use on their own, and only exist to support the main program class.

So, for example, if you want to do some additional syntax checking for brs files, it would make more sense to add program.onBeforeParseFile and program.onAfterParseFile handlers to allow external programs (like preprocessors) to tack on additional functionality.

So could you clarify what it is you are trying to do, and we can go from there?

georgejecook commented 5 years ago

Yes, I agree, I should be more specific - the onAfterParseFile hook is useful as well. I'm most interested in the XmlFile, and it's imports - I'm not sure how I can access that currently, seeing as it's not exported. Not sure if the context would be required as well..

georgejecook commented 5 years ago

I'm trying to use it like this

let programbuilder = new Program({ cwd: projectDir });

    this.fileMap.getAllDescriptors().filter((descriptor) => descriptor.fileType === FileType.CodeBehind)
      .forEach(async (descriptor) => {
        await programbuilder.addOrReplaceFile(descriptor.fullPath);
        //includeImporter.identifyImports(descriptor);
      });

    this.fileMap.getAllDescriptors().filter((descriptor) => descriptor.fileType === FileType.CodeBehind)
      .forEach((descriptor) => {
        includeImporter.addImportIncludes(descriptor);
      });
  }

Perhaps the issue is that there's no documentation on no-cli usage.

georgejecook commented 5 years ago

and this crashes out for me, btw - util is undefined

‌‌util.normalizeAndResolveConfig
‌ReferenceError: util is not defined
    at eval (eval at <anonymous> (/Users/georgecook/Documents/h7ci/hope/opensource/brightscript-language/dist/ProgramBuilder.js:122:25), <anonymous>:1:1)
    at ProgramBuilder.<anonymous> (/Users/georgecook/Documents/h7ci/hope/opensource/brightscript-language/dist/ProgramBuilder.js:122:25)
    at step (/Users/georgecook/Documents/h7ci/hope/opensource/brightscript-language/dist/ProgramBuilder.js:43:23)
    at Object.next (/Users/georgecook/Documents/h7ci/hope/opensource/brightscript-language/dist/ProgramBuilder.js:24:53)
    at /Users/georgecook/Documents/h7ci/hope/opensource/brightscript-language/dist/ProgramBuilder.js:18:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/georgecook/Documents/h7ci/hope/opensource/brightscript-language/dist/ProgramBuilder.js:14:12)
    at ProgramBuilder.run (/Users/georgecook/Documents/h7ci/hope/opensource/brightscript-language/dist/ProgramBuilder.js:114:16)
    at ProjectProcessor.<anonymous> (/Users/georgecook/Documents/h7ci/hope/brsxmlc/src/lib/ProjectProcessor.ts:88:19)
    at Generator.next (<anonymous>)
    at /Users/georgecook/Documents/h7ci/hope/brsxmlc/src/lib/ProjectProcessor.ts:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/georgecook/Documents/h7ci/hope/brsxmlc/src/lib/ProjectProcessor.ts:3:12)
    at ProjectProcessor.processImports (/Users/georgecook/Documents/h7ci/hope/brsxmlc/src/lib/ProjectProcessor.ts:72:16)
    at Suite.<anonymous> (/Users/georgecook/Documents/h7ci/hope/brsxmlc/src/lib/ProjectProcessor.spec.ts:154:23)
georgejecook commented 5 years ago

I've managed to get it incorporated into my code; but I had to edit index.ts, thusly:

export * from './ProgramBuilder';
export * from './Program';
export * from './Context';
export * from './files/BrsFile';
export * from './files/XmlFile';
export { Util, util } from './util';
export { Watcher } from './Watcher';
export * from './interfaces';
export * from './LanguageServer';
export * from './XmlContext';
georgejecook commented 5 years ago

and export class Util

that's been enough for me to do what I needed to do..

TwitchBronBron commented 5 years ago

Cool! The latest release incorporates your suggested exports above.