Skip to content

Commit

Permalink
Strict mode precompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats authored and Chris Garrett committed Nov 13, 2020
1 parent 022b586 commit 8e11b91
Show file tree
Hide file tree
Showing 188 changed files with 11,481 additions and 4,844 deletions.
65 changes: 61 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2019
"ecmaVersion": 2020
},
"extends": [
"eslint:recommended",
Expand Down Expand Up @@ -30,7 +30,9 @@
"qunit/no-global-module-test": "off",
// disabled due to false positives
"qunit/no-global-stop-start": "off",

"import/no-extraneous-dependencies": ["error"],
// this is handled by import/no-extraneous-dependencies
"node/no-extraneous-import": "off",
"prettier/prettier": "error",
"accessor-pairs": "error",
"array-callback-return": "error",
Expand Down Expand Up @@ -73,7 +75,7 @@
"no-bitwise": "error",
"no-caller": "error",
"no-catch-shadow": "error",
"no-console": "off",
"no-console": "error",
"no-continue": "error",
"no-div-regex": "error",
"no-duplicate-imports": "error",
Expand Down Expand Up @@ -186,6 +188,57 @@
"@typescript-eslint/no-unused-vars": "error"
},
"overrides": [
{
"parserOptions": {
"project": "./tsconfig.json"
},
"files": ["packages/@glimmer/compiler/**/*.ts", "packages/@glimmer/syntax/lib/**/*.ts", "packages/@glimmer/syntax/index.ts"],
"extends": [
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/typescript",
"plugin:qunit/recommended",
"plugin:qunit/two",
"plugin:node/recommended",
"prettier",
"prettier/@typescript-eslint"
],
"plugins": [
"simple-import-sort"
],
"rules": {
"prefer-const": ["off"],
"simple-import-sort/sort": ["error"],
"import/order": "off",
"sort-imports": "off",
"import/first": ["error"],
"import/newline-after-import": ["error"],
"import/no-duplicates": ["error"],
"import/export": "off",
"qunit/no-global-expect": ["off"],
// this is handled by import/errors
"node/no-extraneous-import": "off",
"@typescript-eslint/unbound-method": [
"error",
{
"ignoreStatic": true
}
],
"@typescript-eslint/no-explicit-any": [
"error", {
"ignoreRestArgs": true
}
],
"@typescript-eslint/ban-types": ["error", {
"extendDefaults": true,
"types": {
"object": false
}
}]
}
},
{
"files": ["**/*.d.ts"],
"parserOptions": {
Expand All @@ -209,6 +262,9 @@
"env": {
"es6": true,
"node": true
},
"rules": {
"no-console": "off"
}
},
// bin scripts
Expand All @@ -229,7 +285,8 @@
"sourceType": "module"
},
"rules": {
"node/no-unsupported-features/es-syntax": "off"
"node/no-unsupported-features/es-syntax": "off",
"no-console": "off"
}
},
// source packages
Expand Down
7 changes: 7 additions & 0 deletions .madgerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"detectiveOptions": {
"ts": {
"skipTypeImports": true
}
}
}
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"files.exclude": {
"**/.DS_Store": true,
"**/.git": true,
"node_modules/**": true,
"tmp/**": true
},
"files.watcherExclude": {
Expand All @@ -28,5 +29,11 @@
"javascript.preferences.importModuleSpecifier": "relative",
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.workspaceSymbols.scope": "currentProject",
"eslint.workingDirectories": [{ "mode": "auto" }]
"eslint.workingDirectories": [
{
"directory": ".",
"changeProcessCWD": true
}
],
"eslint.enable": true
}
Empty file modified bin/yarn-link-local.js
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@
"broccoli-plugin": "^3.1.0",
"broccoli-rollup": "^4.1.1",
"broccoli-source": "^3.0.0",
"broccoli-typescript-compiler": "^6.0.0",
"broccoli-typescript-compiler": "^6.0.1",
"chalk": "^3.0.0",
"dag-map": "^2.0.2",
"ember-cli": "~3.20.0",
"ember-cli-browserstack": "^1.1.0",
"ensure-posix-path": "^1.1.1",
"eslint": "^7.7.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-qunit": "^4.3.0",
"eslint-plugin-simple-import-sort": "^5.0.3",
"execa": "^1.0.0",
"glob": "^7.0.5",
"js-yaml": "^3.10.0",
Expand Down Expand Up @@ -157,7 +159,7 @@
},
"volta": {
"node": "12.18.3",
"yarn": "1.22.4"
"yarn": "1.22.5"
},
"ember-addon": {
"paths": [
Expand Down
10 changes: 3 additions & 7 deletions packages/@glimmer/compiler/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { defaultId, precompile, PrecompileOptions } from './lib/compiler';
export { defaultId, precompile, precompileJSON } from './lib/compiler';
export {
ProgramSymbols,
buildStatement,
Expand All @@ -7,12 +7,8 @@ export {
c,
unicode,
NEWLINE,
} from './lib/builder';
export { BuilderStatement, Builder } from './lib/builder-interface';
export { default as TemplateCompiler } from './lib/template-compiler';
} from './lib/builder/builder';
export { BuilderStatement, Builder } from './lib/builder/builder-interface';

// exported only for tests
export { default as TemplateVisitor } from './lib/template-visitor';
export { default as WireFormatDebugger } from './lib/wire-format-debug';

export * from './lib/location';
23 changes: 23 additions & 0 deletions packages/@glimmer/compiler/lib/PASSES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The Glimmer preprocessor is responsible for taking templates and converting them into the Wire Format.

The input to the preprocessor is _the AST_. The AST is the result of parsing a template via `@glimmer/syntax`.

> The preprocessor uses AST v2. See the README in @glimmer/syntax for more information.
## Passes

**Normalization**: The normalization pass turns the AST into the HIR (high-level IR). While the AST treats all blocks, curlies and expressions equally, the HIR has special instructions for keywords (such as `#in-element`, `{{yield}}` and `(has-block)`).

**Symbol Allocation**: The symbol allocation pass turns the HIR into the MIR (mid-level IR). While HIR instructions use strings to identify variable bindings and references, the MIR uses unique symbols for each binding and reference, eliminating the need to understand the current scope stack in order to resolve the location of a variable reference.

> The MIR is a representation of the encoded wire format before serializing the instructions, and with source offsets still attached to each instruction.
In addition to allocating symbols for variable references that refer to in-scope bindings (introduced by block parameters), this pass also allocates symbols for `@arg` references, as well as blocks that are references via the `{{yield}}`, `(has-block)` and `(has-block-params)` keywords.

Finally, this pass is responsible for identifying the presence of the `{{partial}}` and `{{debugger}}` keywords, which require symbol maps at runtime.

**Encoding**: The encoding pass turns the MIR into the wire format, which is suitable for wire transport. The current encoding pass is hardcoded to emit the wire format (documented in `@glimmer/wire-format`). This is the stage where any optimizations on the representation are performed (like erasing trailing nulls, or other simple packing optimizations).

In strict mode, encoded templates will need to be emitted into a JavaScript file containing variable bindings that correspond to each of the upvars. This is not yet implemented.

In the future, it will be possible to replace the encoder with an arbitrary encoding pass, provided that you supply a runtime decoder.
Loading

0 comments on commit 8e11b91

Please sign in to comment.