Skip to content

Refactor: No more than 1 namespace declaration per file #35373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 27, 2019

Conversation

weswigham
Copy link
Member

This refactors our codebase to conform to and adds a lint rule to enforce a file having at most one top level namespace declaration. This makes the translation into modules much easier (and this refactor wasn't easily automatable, as some split namespaces existed to accomplish scope workarounds, which had to be done differently), as it means I don't have to track scope conflicts or what's exported from where when transforming the namespaces.

The primary effect of this is that a bunch of core utility files now have a clean split between their @internal and public halves. Hopefully this'll have the beneficial side-effect of making it much more obvious what's public vs what isn't when you're authoring new utilities.

This also slightly changes how we do some shim stuff in the harness, so that code will be more stable when it migrates from namespaces to modules - namely, no longer relying on namespace Foo making a global Foo to patch things into the global scope.

@weswigham
Copy link
Member Author

@typescript-bot pack this just to validate that renaming core.ts didn't break package generation or anything

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 26, 2019

Heya @weswigham, I've started to run the tarball bundle task on this PR at 083bcd2. You can monitor the build here. It should now contribute to this PR's status checks.

@weswigham
Copy link
Member Author

@typescript-bot pack this now that lint's fixed

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 26, 2019

Heya @weswigham, I've started to run the tarball bundle task on this PR at 1698f40. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 26, 2019

Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/55741/artifacts?artifactName=tgz&fileId=A4E51EF5DF6AAF190F6539555E36CBDF7277B4494D1AD63516C597F5DB1DBD3C02&fileName=/typescript-3.8.0-insiders.20191126.tgz"
    }
}

and then running npm install.


There is also a playground for this build.

@@ -0,0 +1,160 @@
namespace ts {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x.ts/xPublic.ts is a fine naming scheme except that it makes bash-style completions worse because bu doesn't produce a filename.

One solution is to use a public- prefix, which also seems bad. Or maybe a subdirectory. I don't really have any good ideas. Maybe this situation is temporary? I hope?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like @sandersn 's idea of subfolder for internal. If we are not making subfolder i would like having xInternal and x so the file names exposes at smaller scale are nicer and without public

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK except for new file names.

/* eslint-disable no-var */

// this will work in the browser via browserify
var _chai: typeof chai = require("chai");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

along the same lines, these files should probably be named global/languageService/utils.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is all test harness setup...?

// @ts-ignore
if (typeof process === "undefined" || process.browser) {
/// TODO: this is used by VS, clean this up on both sides of the interface
//@ts-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed feelings about ts-ignore in ts file in Typescript codebase...

Copy link
Member Author

@weswigham weswigham Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, we're doing things that are untyped here (and the typed "fix" is actually declaring these fields as globals, which I'd rather not do), so we need the bailout. It's also not our first - we already have one in the mapShim file to suppress an "unused type parameter" error (and is needed because said interface later merges with another in a dependent project where the param is actually used).

/* @internal */
namespace ts {
// These utilities are common to multiple language service features.
//#region
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does VS Code support #region ??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea

@weswigham weswigham merged commit c447ebc into microsoft:master Nov 27, 2019
@weswigham weswigham deleted the one-namespace-per-module branch November 27, 2019 21:44
"utilities.ts",
"watchType.ts"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weswigham Comma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants