├── .gitignore
├── .npmrc
├── .travis.yml
├── .yarnrc
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Gruntfile.js
├── LICENSE.md
├── NOTICE.md
├── README.md
├── commitlint.config.js
├── docs
├── ARCHITECTURE.md
└── DEVELOPING.md
├── greenkeeper.json
├── lerna.json
├── opticss.code-workspace
├── package.json
├── packages
├── @opticss
│ ├── attr-analysis-dsl
│ │ ├── .npmignore
│ │ ├── .vscode
│ │ │ ├── cSpell.json
│ │ │ ├── launch.json
│ │ │ ├── settings.json
│ │ │ └── tasks.json
│ │ ├── CHANGELOG.md
│ │ ├── grammar
│ │ │ ├── attrlexer.js
│ │ │ ├── attrvalue.js
│ │ │ └── attrvalue.ne
│ │ ├── package.json
│ │ ├── src
│ │ │ ├── AttributeValueParser.ts
│ │ │ └── index.ts
│ │ ├── test
│ │ │ ├── mocha.opts
│ │ │ └── parser-test.ts
│ │ ├── tsconfig.json
│ │ ├── tslint.cli.json
│ │ ├── tslint.json
│ │ └── tslint.release.json
│ ├── code-style
│ │ ├── .vscode
│ │ │ ├── launch.json
│ │ │ └── settings.json
│ │ ├── CHANGELOG.md
│ │ ├── README.md
│ │ ├── configs
│ │ │ ├── tslint.cli.json
│ │ │ ├── tslint.interactive.json
│ │ │ └── tslint.release.json
│ │ ├── package.json
│ │ ├── src
│ │ │ ├── index.ts
│ │ │ └── rules
│ │ │ │ ├── index.ts
│ │ │ │ ├── multilineParametersRule.ts
│ │ │ │ ├── preferUnknownToAnyRule.ts
│ │ │ │ └── preferWhateverToAnyRule.ts
│ │ ├── test
│ │ │ └── rules
│ │ │ │ ├── multiline-parameters
│ │ │ │ ├── args.ts.fix
│ │ │ │ ├── args.ts.lint
│ │ │ │ └── tslint.json
│ │ │ │ ├── prefer-unknown-to-any
│ │ │ │ ├── test.ts.lint
│ │ │ │ └── tslint.json
│ │ │ │ └── tslint-test.json
│ │ ├── tsconfig.json
│ │ ├── tslint.cli.json
│ │ ├── tslint.json
│ │ └── tslint.release.json
│ ├── demo-app
│ │ ├── .babelrc
│ │ ├── .gitignore
│ │ ├── .npmignore
│ │ ├── CHANGELOG.md
│ │ ├── bin
│ │ │ └── opticss
│ │ ├── package.json
│ │ ├── server.js
│ │ ├── src
│ │ │ ├── css-size-fake.ts
│ │ │ ├── demos.ts
│ │ │ ├── index.ts
│ │ │ └── simple-example.ts
│ │ ├── static
│ │ │ ├── app.css
│ │ │ └── index.html
│ │ ├── test
│ │ │ ├── demo-test.ts
│ │ │ └── mocha.opts
│ │ ├── tsconfig.json
│ │ ├── tslint.cli.json
│ │ ├── tslint.json
│ │ ├── tslint.release.json
│ │ └── types-local
│ │ │ └── codemirror
│ │ │ ├── index.d.ts
│ │ │ └── package.json
│ ├── element-analysis
│ │ ├── .vscode
│ │ │ ├── cSpell.json
│ │ │ ├── launch.json
│ │ │ ├── settings.json
│ │ │ └── tasks.json
│ │ ├── CHANGELOG.md
│ │ ├── package.json
│ │ ├── src
│ │ │ ├── Attribute.ts
│ │ │ ├── Element.ts
│ │ │ ├── SourceLocation.ts
│ │ │ ├── Tagname.ts
│ │ │ ├── attrValues.ts
│ │ │ └── index.ts
│ │ ├── test
│ │ │ ├── element-analysis-test.ts
│ │ │ └── mocha.opts
│ │ ├── tsconfig.json
│ │ ├── tslint.cli.json
│ │ ├── tslint.json
│ │ ├── tslint.release.json
│ │ └── yarn-error.log
│ ├── simple-template
│ │ ├── .npmignore
│ │ ├── .vscode
│ │ │ ├── cSpell.json
│ │ │ ├── launch.json
│ │ │ ├── settings.json
│ │ │ └── tasks.json
│ │ ├── CHANGELOG.md
│ │ ├── package.json
│ │ ├── src
│ │ │ ├── SimpleAnalyzer.ts
│ │ │ ├── SimpleTemplateRewriter.ts
│ │ │ ├── SimpleTemplateRunner.ts
│ │ │ ├── TestTemplate.ts
│ │ │ └── index.ts
│ │ ├── test
│ │ │ ├── mocha.opts
│ │ │ ├── simple-template-runner-test.ts
│ │ │ ├── simple-template-test.ts
│ │ │ └── template-analysis-test.ts
│ │ ├── tsconfig.json
│ │ ├── tslint.cli.json
│ │ ├── tslint.json
│ │ └── tslint.release.json
│ ├── template-api
│ │ ├── .vscode
│ │ │ ├── cSpell.json
│ │ │ ├── launch.json
│ │ │ ├── settings.json
│ │ │ └── tasks.json
│ │ ├── CHANGELOG.md
│ │ ├── package.json
│ │ ├── src
│ │ │ ├── BooleanExpression.ts
│ │ │ ├── StyleMapping.ts
│ │ │ ├── TemplateError.ts
│ │ │ ├── TemplateIntegrationOptions.ts
│ │ │ └── index.ts
│ │ ├── test
│ │ │ ├── mocha.opts
│ │ │ ├── style-mapping-test.ts
│ │ │ └── template-api.ts
│ │ ├── tsconfig-test.json
│ │ ├── tsconfig.json
│ │ ├── tslint.cli.json
│ │ ├── tslint.json
│ │ └── tslint.release.json
│ └── util
│ │ ├── .vscode
│ │ ├── cSpell.json
│ │ ├── launch.json
│ │ ├── settings.json
│ │ └── tasks.json
│ │ ├── CHANGELOG.md
│ │ ├── package.json
│ │ ├── src
│ │ ├── IdentityDictionary.ts
│ │ ├── Maybe.ts
│ │ ├── MultiMap.ts
│ │ ├── OptiCSSError.ts
│ │ ├── TwoKeyMultiMap.ts
│ │ ├── UtilityTypes.ts
│ │ ├── assertNever.ts
│ │ ├── clean.ts
│ │ ├── flatten.ts
│ │ ├── index.ts
│ │ ├── typedAssert.ts
│ │ └── unionInto.ts
│ │ ├── test
│ │ ├── maybe-test.ts
│ │ ├── mocha.opts
│ │ ├── util-test.ts
│ │ └── utility-types-test.ts
│ │ ├── tsconfig.json
│ │ ├── tslint.cli.json
│ │ ├── tslint.json
│ │ └── tslint.release.json
├── opticss
│ ├── .vscode
│ │ ├── cSpell.json
│ │ ├── launch.json
│ │ ├── settings.json
│ │ └── tasks.json
│ ├── ARCHITECTURE.md
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ ├── Actions
│ │ │ ├── Action.ts
│ │ │ ├── actions
│ │ │ │ ├── AnnotateMergeConflict.ts
│ │ │ │ ├── ChangeSelector.ts
│ │ │ │ ├── ExpandShorthand.ts
│ │ │ │ ├── MarkAttributeValueObsolete.ts
│ │ │ │ ├── MergeDeclarations.ts
│ │ │ │ ├── Note.ts
│ │ │ │ ├── RemoveRule.ts
│ │ │ │ ├── RewriteRuleIdents.ts
│ │ │ │ └── Warning.ts
│ │ │ └── index.ts
│ │ ├── CssFile.ts
│ │ ├── Match
│ │ │ ├── AttributeMatcher.ts
│ │ │ ├── ElementMatcher.ts
│ │ │ ├── Match.ts
│ │ │ ├── Matcher.ts
│ │ │ ├── TagMatcher.ts
│ │ │ └── index.ts
│ │ ├── OpticssOptions.ts
│ │ ├── OptimizationPass.ts
│ │ ├── Optimizer.ts
│ │ ├── errors.ts
│ │ ├── index.ts
│ │ ├── initializers
│ │ │ ├── index.ts
│ │ │ └── initKnownIdents.ts
│ │ ├── optimizations
│ │ │ ├── MergeDeclarations
│ │ │ │ ├── DeclarationMapper.ts
│ │ │ │ ├── OptimizationContext.ts
│ │ │ │ ├── StyleInfo.ts
│ │ │ │ └── index.ts
│ │ │ ├── Optimization.ts
│ │ │ ├── RemoveUnusedStyles.ts
│ │ │ ├── RewriteIdents.ts
│ │ │ └── index.ts
│ │ ├── parseSelector.ts
│ │ ├── query.ts
│ │ └── util
│ │ │ ├── IdentGenerator.ts
│ │ │ ├── adaptSourceMap.ts
│ │ │ ├── cssIntrospection.ts
│ │ │ └── shorthandProperties.ts
│ ├── test
│ │ ├── fixtures
│ │ │ └── integration-tests
│ │ │ │ └── simple
│ │ │ │ ├── markup.html
│ │ │ │ └── styles.css
│ │ ├── integration-tests.ts
│ │ ├── mocha.opts
│ │ ├── opticss-test.ts
│ │ ├── optimizations
│ │ │ ├── all-optimizations-test.ts
│ │ │ ├── merge-declarations-test.ts
│ │ │ ├── remove-unused-styles-test.ts
│ │ │ └── rewrite-idents-test.ts
│ │ ├── parse-selector-test.ts
│ │ ├── styleable-test.ts
│ │ └── util
│ │ │ ├── assertCascade.ts
│ │ │ ├── assertSmaller.ts
│ │ │ ├── clean.ts
│ │ │ ├── input.txt
│ │ │ └── randomness.ts
│ ├── tsconfig.json
│ ├── tslint.cli.json
│ ├── tslint.json
│ ├── tslint.release.json
│ └── types-local
│ │ ├── concat-with-sourcemaps
│ │ ├── index.d.ts
│ │ └── package.json
│ │ └── css-size
│ │ ├── index.d.ts
│ │ └── package.json
└── resolve-cascade
│ ├── .npmignore
│ ├── .vscode
│ ├── launch.json
│ ├── settings.json
│ └── tasks.json
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── docs
│ ├── README.md
│ ├── classes
│ │ ├── resolve_cascade.cascade.md
│ │ ├── resolve_cascade.elementstyle.md
│ │ ├── resolve_cascade.elementstylemismatch.md
│ │ └── resolve_cascade.markupmismatcherror.md
│ └── interfaces
│ │ ├── resolve_cascade.assertionresult.md
│ │ ├── resolve_cascade.cascadeinformation.md
│ │ ├── resolve_cascade.computedstyle.md
│ │ ├── resolve_cascade.matchedselector.md
│ │ ├── resolve_cascade.pseudostates.md
│ │ └── resolve_cascade.styledpseudoelements.md
│ ├── package.json
│ ├── src
│ ├── Cascade.ts
│ ├── assertCascade.ts
│ ├── index.ts
│ └── util.ts
│ ├── test
│ ├── assert-cascade-test.ts
│ ├── cascade-test.ts
│ ├── clean.ts
│ └── mocha.opts
│ ├── tsconfig.json
│ ├── tslint.cli.json
│ ├── tslint.json
│ └── tslint.release.json
├── tsconfig.json
├── tslint.json
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | dist/
3 | coverage/
4 | build/
5 | .DS_Store
6 | packages/css-property-parser
7 | yarn-error.log
8 | lerna-debug.log
9 | tsconfig.tsbuildinfo
10 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | registry=https://registry.npmjs.org/
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | if: tag IS blank
2 | git:
3 | depth: 1
4 | sudo: false
5 | language: node_js
6 | node_js:
7 | - "8"
8 | - "10"
9 | - "12"
10 |
11 | before_install:
12 | - npm install -g lerna yarn
13 |
14 | install:
15 | - lerna bootstrap --registry=https://registry.npmjs.org/
16 |
17 | script:
18 | - commitlint-travis
19 | - lerna run test
20 |
--------------------------------------------------------------------------------
/.yarnrc:
--------------------------------------------------------------------------------
1 | -install.check-files true
2 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contribution Agreement
2 | ======================
3 |
4 | As a contributor, you represent that the code you submit is your
5 | original work or that of your employer (in which case you represent you
6 | have the right to bind your employer). By submitting code, you (and, if
7 | applicable, your employer) are licensing the submitted code to LinkedIn
8 | and the open source community subject to the BSD 2-Clause license.
9 |
10 | Getting Started
11 | ===============
12 |
13 | Install required global dependencies:
14 |
15 | ```
16 | $ npm install -g lerna yarn
17 | ```
18 |
19 | Check out the code:
20 |
21 | ```
22 | $ git clone https://github.com/linkedin/opticss.git
23 | ```
24 |
25 | Go into the `opticss` directory and install dependencies
26 | and make sure all the tests are passing.
27 |
28 | ```
29 | $ cd opticss
30 | $ lerna bootstrap
31 | $ lerna run test
32 | ```
33 |
34 | The code for individual packages of this monorepo are in `packages/*`.
35 | Within any of the packages in this monorepo you'll generally use the npm
36 | package scripts to manage the project, E.g. `yarn run test` or
37 | `yarn run lintfix`. Run `yarn run` for a list of available commands.
38 |
39 |
40 | Responsible Disclosure of Security Vulnerabilities
41 | ==================================================
42 |
43 | **Do not file an issue on Github for security issues.** Please review
44 | the [guidelines for disclosure][disclosure_guidelines]. Reports should
45 | be encrypted using PGP ([public key][pubkey]) and sent to
46 | [security@linkedin.com][disclosure_email] preferably with the title
47 | "Vulnerability in Github LinkedIn/opticss - <short summary>".
48 |
49 |
50 | Tips for Getting Your Pull Request Accepted
51 | ===========================================
52 |
53 | 1. Make sure all new features are tested and the tests pass.
54 | 2. Bug fixes must include a test case demonstrating the error that it fixes.
55 | 3. Open an issue first and seek advice for your change before submitting
56 | a pull request. Large features which have never been discussed are
57 | unlikely to be accepted. **You have been warned.**
58 |
59 | [disclosure_guidelines]: https://www.linkedin.com/help/linkedin/answer/62924
60 | [pubkey]: https://gist.github.com/chriseppstein/3f45d3a8e6fb42f24cb7b3f77f21381e
61 | [disclosure_email]: mailto:security@linkedin.com?subject=Vulnerability%20in%20Github%20LinkedIn/opticss%20-%20%3Csummary%3E
62 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | const shell = require("shelljs");
2 | module.exports = function(grunt) {
3 | grunt.initConfig({
4 | release: {
5 | options: {
6 | npm: false,
7 | afterRelease: ['publish']
8 | }
9 | },
10 | });
11 | grunt.loadNpmTasks('grunt-release');
12 | grunt.registerTask('publish', "Publish to NPM", function() {
13 | shell.exec('li-npm-publish');
14 | });
15 | };
16 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | BSD 2-CLAUSE LICENSE
2 |
3 | Copyright 2018 LinkedIn Corporation and Contributors.
4 | All Rights Reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
--------------------------------------------------------------------------------
/NOTICE.md:
--------------------------------------------------------------------------------
1 | Copyright 2018 LinkedIn Corporation and Contributors
2 | All Rights Reserved.
3 |
4 | Licensed under the BSD 2-Clause License (the "License").
5 | See LICENSE in the project root for license information.
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | OptiCSS
2 | =======
3 |
4 | [](https://greenkeeper.io/)
5 |
6 | ### OptiCSS is a template-aware stylesheet optimizer.
7 |
8 | Most developers don't use OptiCSS directly. You may be looking for a style framework that uses it:
9 |
10 | * [CSS Blocks](http://css-blocks.com/)
11 | * *Add your project to this list! We want to collaborate with you on adopting OptiCSS.*
12 |
13 | Overall [architecture documentation](./docs/ARCHITECTURE.md).
14 |
15 | This is a monorepo, there's different documentation available in the various packages:
16 |
17 | ### Public API & Libraries:
18 |
19 | These packages are what we expect others to have dependencies on. We are careful about their public APIs and backwards compatibility.
20 |
21 | * `opticss`: The core library containing the optimizer. [README](./packages/opticss/README.md)
22 | * `template-api` - The template analysis API.
23 | * `element-analysis`: The element analysis API.
24 | * `resolve-cascade` - A library that produces a resolved cascade for CSS
25 | selectors against a DOM without using a browser. [README](./packages/resolve-cascade/README.md)
26 | * `util` - Common utilities and data structures that we share across our project.
27 |
28 | ### Internal Dependencies:
29 |
30 | These packages are extracted to allow them to be shared. You probably won't
31 | need to depend on them. As long as the other packages in this monorepo
32 | compile and pass tests we don't worry about backwards incompatibilty for
33 | these.
34 |
35 | * `simple-template` - A custom template language we use for testing OptiCSS.
36 | * `attr-analysis-dsl` - A custom DSL for expressing attribute analysis succinctly.
37 | * `code-style`: The coding styleguide and linters for OptiCSS. [README](./packages/@opticss/code-style/README.md)
38 |
39 | ### Miscellany
40 | * `demo-app`: An interactive demo of OptiCSS.
--------------------------------------------------------------------------------
/commitlint.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ['@commitlint/config-conventional'],
3 | rules: {
4 | 'subject-full-stop': [2, 'always', '.'],
5 | 'subject-case': [
6 | 2, 'always',
7 | ['sentence-case']
8 | ]
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/docs/DEVELOPING.md:
--------------------------------------------------------------------------------
1 | Developing Software That Uses OptiCSS
2 | =====================================
3 |
4 | OptiCSS is written in TypeScript and we expect that the code that integrates with it non-trivially will also be written in TypeScript. Except in rare cases, the runtime code does not check for invalid arguments or bad data -- that's what the type checker is for.
5 |
--------------------------------------------------------------------------------
/greenkeeper.json:
--------------------------------------------------------------------------------
1 | {
2 | "groups": {
3 | "default": {
4 | "packages": [
5 | "package.json",
6 | "packages/@opticss/attr-analysis-dsl/package.json",
7 | "packages/@opticss/code-style/package.json",
8 | "packages/@opticss/demo-app/package.json",
9 | "packages/@opticss/demo-app/types-local/codemirror/package.json",
10 | "packages/@opticss/element-analysis/package.json",
11 | "packages/@opticss/simple-template/package.json",
12 | "packages/@opticss/template-api/package.json",
13 | "packages/@opticss/util/package.json",
14 | "packages/opticss/package.json",
15 | "packages/opticss/types-local/concat-with-sourcemaps/package.json",
16 | "packages/resolve-cascade/package.json"
17 | ]
18 | }
19 | },
20 | "ignore": [
21 | "@types/node"
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "independent",
3 | "npmClient": "yarn",
4 | "useWorkspaces": true,
5 | "packages": [
6 | "packages/*",
7 | "packages/@opticss/*"
8 | ],
9 | "command": {
10 | "publish": {
11 | "message": "chore(release): Publish packages.",
12 | "conventionalCommits": true,
13 | "sort": true
14 | },
15 | "bootstrap": {
16 | "sort": true
17 | },
18 | "run": {
19 | "sort": true
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/opticss.code-workspace:
--------------------------------------------------------------------------------
1 | {
2 | "folders": [
3 | {
4 | "path": "packages/@opticss/attr-analysis-dsl"
5 | },
6 | {
7 | "path": "packages/@opticss/demo-app"
8 | },
9 | {
10 | "path": "packages/@opticss/element-analysis"
11 | },
12 | {
13 | "path": "packages/opticss"
14 | },
15 | {
16 | "path": "packages/resolve-cascade"
17 | },
18 | {
19 | "path": "packages/@opticss/simple-template"
20 | },
21 | {
22 | "path": "packages/@opticss/template-api"
23 | },
24 | {
25 | "path": "packages/@opticss/util"
26 | },
27 | {
28 | "path": "packages/@opticss/code-style"
29 | },
30 | {
31 | "path": "docs"
32 | },
33 | {
34 | "path": "."
35 | }
36 | ],
37 | "settings": {
38 | "cSpell.ignorePaths": [
39 | "**/node_modules/**",
40 | "**/vscode-extension/**",
41 | "**/.git/**",
42 | ".vscode",
43 | "typings",
44 | "**/*.json"
45 | ],
46 | "typescript.tsdk": "opticss/node_modules/typescript/lib",
47 | "cSpell.words": [
48 | "Opti",
49 | "stylesheet",
50 | "unoptimized"
51 | ],
52 | "files.exclude": {
53 | "**/dist": true
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "name": "opticss",
4 | "devDependencies": {
5 | "@commitlint/cli": "^7.5.2",
6 | "@commitlint/config-conventional": "^7.5.0",
7 | "@commitlint/travis-cli": "^7.5.2",
8 | "husky": "^2.2.0",
9 | "lerna": "^3.13.2"
10 | },
11 | "scripts": {
12 | "bootstrap": "lerna bootstrap",
13 | "commitmsg": "commitlint --edit $GIT_PARAMS",
14 | "cleandist": "lerna list --toposort -l | awk '{ print $3\"/dist\" }' | xargs rm -rf",
15 | "test": "lerna run test"
16 | },
17 | "workspaces": [
18 | "packages/*",
19 | "packages/@opticss/*"
20 | ],
21 | "greenkeeper": {
22 | "commitMessages": {
23 | "addConfigFile": "chore(greenkeeper): Add Greenkeeper config file.",
24 | "updateConfigFile": "chore(greenkeeper): Update Greenkeeper config file.",
25 | "initialBadge": "docs(greenkeeper): Add Greenkeeper badge.",
26 | "initialDependencies": "chore(greenkeeper): Update dependencies.",
27 | "initialBranches": "chore(greenkeeper): Whitelist greenkeeper branches.",
28 | "dependencyUpdate": "chore(greenkeeper): Update ${dependency} to version ${version}.",
29 | "devDependencyUpdate": "chore(greenkeeper): Update ${dependency} to version ${version}.",
30 | "dependencyPin": "chore(greenkeeper): Pin ${dependency} to ${oldVersion}.",
31 | "devDependencyPin": "chore(greenkeeper): Pin ${dependency} to ${oldVersion}.",
32 | "lockfileUpdate": "chore(greenkeeper): Update ${lockfilePath}.",
33 | "closes": "\n\nCloses #${number}."
34 | }
35 | },
36 | "volta": {
37 | "node": "10.15.3",
38 | "yarn": "1.15.2"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/.npmignore:
--------------------------------------------------------------------------------
1 | src/
2 | test/
3 | ts*.json
4 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/.vscode/cSpell.json:
--------------------------------------------------------------------------------
1 | // cSpell Settings
2 | {
3 | // Version of the setting file. Always 0.1
4 | "version": "0.1",
5 | // language - current active spelling language
6 | "language": "en",
7 | // words - list of words to be always considered correct
8 | "words": [
9 | "Rewriteable",
10 | "opticss"
11 | ],
12 | // flagWords - list of words to be always considered incorrect
13 | // This is useful for offensive words and common spelling errors.
14 | // For example "hte" should be "the"
15 | "flagWords": []
16 | }
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible Node.js debug attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "node",
9 | "request": "launch",
10 | "name": "Launch Program",
11 | "preLaunchTask": "compile",
12 | "program": "${workspaceRoot}/node_modules/.bin/_mocha",
13 | "args": [
14 | "dist/test",
15 | "--opts",
16 | "test/mocha.opts"
17 | ],
18 | "cwd": "${workspaceRoot}",
19 | "outFiles": [
20 | "${workspaceRoot}/dist/**/*.js"
21 | ],
22 | "sourceMaps": true
23 | }
24 | ]
25 | }
26 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | // Place your settings in this file to overwrite default and user settings.
2 | {
3 | "files.exclude": {
4 | "**/dist/**/*": true,
5 | "**/*.lock": true
6 | },
7 | "editor.tabSize": 2,
8 | "typescriptHero.codeOutline.enabled": true,
9 | "typescriptHero.resolver.multiLineWrapThreshold": 10,
10 | "typescriptHero.resolver.multiLineTrailingComma": true,
11 | "typescriptHero.resolver.organizeOnSave": true,
12 | "tslint.configFile": "tslint.json",
13 | "tslint.enable": true,
14 | "cSpell.words": [
15 | "Rewriteable"
16 | ],
17 | "tslint.packageManager": "yarn",
18 | "npm.packageManager": "yarn"
19 | }
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "label": "compile",
8 | "type": "npm",
9 | "script": "compile",
10 | "problemMatcher": []
11 | }
12 | ]
13 | }
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file.
4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5 |
6 | ## [0.6.3](https://github.com/linkedin/opticss/compare/@opticss/attr-analysis-dsl@0.6.2...@opticss/attr-analysis-dsl@0.6.3) (2019-09-16)
7 |
8 | **Note:** Version bump only for package @opticss/attr-analysis-dsl
9 |
10 |
11 |
12 |
13 |
14 | ## [0.6.2](https://github.com/linkedin/opticss/compare/@opticss/attr-analysis-dsl@0.6.1...@opticss/attr-analysis-dsl@0.6.2) (2019-05-02)
15 |
16 | **Note:** Version bump only for package @opticss/attr-analysis-dsl
17 |
18 |
19 |
20 |
21 |
22 | ## [0.6.1](https://github.com/linkedin/opticss/compare/@opticss/attr-analysis-dsl@0.6.0...@opticss/attr-analysis-dsl@0.6.1) (2019-04-30)
23 |
24 | **Note:** Version bump only for package @opticss/attr-analysis-dsl
25 |
26 |
27 |
28 |
29 |
30 | # [0.6.0](https://github.com/linkedin/opticss/compare/@opticss/attr-analysis-dsl@0.5.0...@opticss/attr-analysis-dsl@0.6.0) (2019-04-25)
31 |
32 | **Note:** Version bump only for package @opticss/attr-analysis-dsl
33 |
34 |
35 |
36 |
37 |
38 | # 0.5.0 (2019-04-19)
39 |
40 |
41 |
42 | # 0.4.0 (2018-10-19)
43 |
44 |
45 | ### Features
46 |
47 | * Manually throw error for Node 6 in Optimizer. ([c4db789](https://github.com/linkedin/opticss/commit/c4db789))
48 |
49 |
50 |
51 | # 0.3.0 (2018-04-24)
52 |
53 |
54 |
55 | # 0.3.0-rc.0 (2018-04-24)
56 |
57 |
58 |
59 |
60 |
61 |
62 | # [0.3.0](https://github.com/linkedin/opticss/compare/v0.3.0-rc.0...v0.3.0) (2018-04-24)
63 |
64 | **Note:** Version bump only for package @opticss/attr-analysis-dsl
65 |
66 |
67 |
68 |
69 |
70 |
71 | # [0.2.0](https://github.com/linkedin/opticss/compare/v0.1.1...v0.2.0) (2017-11-26)
72 |
73 |
74 |
75 |
76 | **Note:** Version bump only for package @opticss/attr-analysis-dsl
77 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/grammar/attrlexer.js:
--------------------------------------------------------------------------------
1 | const moo = require('moo')
2 |
3 | const lexer = moo.compile({
4 | WS: /[ \t]+/,
5 | pipe: '|',
6 | lparen: '(',
7 | rparen: ')',
8 | asterisk: '*',
9 | unknown: '???',
10 | unknownIdentifier: '?',
11 | absent: '---',
12 | constant: /[^|()*\n \t]+/,
13 | });
14 |
15 | module.exports = lexer;
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@opticss/attr-analysis-dsl",
3 | "version": "0.6.3",
4 | "description": "A DSL for writing attribute analysis objects for use in OptiCSS.",
5 | "main": "dist/src/index.js",
6 | "types": "dist/src/index.d.ts",
7 | "scripts": {
8 | "compile": "tsc --build && mkdir -p dist/src/grammar && cp grammar/*.js dist/src/grammar",
9 | "pretest": "yarn run compile",
10 | "prepublishOnly": "yarn run compile && yarn run lintall",
11 | "lint": "tslint -t msbuild --project . -c tslint.cli.json",
12 | "lintall": "tslint -t msbuild --project . -c tslint.release.json",
13 | "lintfix": "tslint -t msbuild --project . -c tslint.cli.json --fix",
14 | "test": "mocha dist/test --opts test/mocha.opts",
15 | "posttest": "yarn run lint",
16 | "coverage": "istanbul cover -i \"dist/src/**/*.js\" -x \"**/grammar/**\" --dir ./build/coverage _mocha -- dist/test --opts test/mocha.opts && yarn run remap",
17 | "remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
18 | "docs": "typedoc --out ./docs .",
19 | "grammar": "nearleyc grammar/attrvalue.ne -o grammar/attrvalue.js"
20 | },
21 | "repository": {
22 | "type": "git",
23 | "url": "git+https://github.com/linkedin/opticss.git"
24 | },
25 | "keywords": [
26 | "css",
27 | "cascade"
28 | ],
29 | "author": "Chris Eppstein",
30 | "license": "BSD-2-Clause",
31 | "bugs": {
32 | "url": "https://github.com/linkedin/opticss/issues?q=is%3Aopen+is%3Aissue+label%3Apkg%3Aelement-analysis+label%3Apkg%3Aattr-analysis-dsl"
33 | },
34 | "homepage": "https://github.com/linkedin/opticss/tree/master/packages/%40opticss/attr-analysis-dsl",
35 | "engines": {
36 | "node": "6.* || 8.* || >= 10.*"
37 | },
38 | "publishConfig": {
39 | "access": "public"
40 | },
41 | "dependencies": {
42 | "@opticss/util": "^0.7.0",
43 | "moo": "^0.5.0",
44 | "nearley": "^2.10.3"
45 | },
46 | "devDependencies": {
47 | "@opticss/code-style": "^0.6.0",
48 | "@opticss/element-analysis": "^0.6.2",
49 | "@types/chai": "^4.0.4",
50 | "@types/mocha": "^5.2.6",
51 | "@types/nearley": "^2.9.0",
52 | "chai": "^4.1.2",
53 | "istanbul": "^0.4.5",
54 | "mocha": "^6.1.4",
55 | "mocha-typescript": "^1.1.9",
56 | "remap-istanbul": "^0.13.0",
57 | "source-map-support": "^0.5.3",
58 | "tslint": "^5.10.0",
59 | "typedoc": "^0.15.0-0",
60 | "typescript": "~3.4.4"
61 | },
62 | "gitHead": "ef310cb1b10dbc90cae4f859da146863f99d940b",
63 | "toolchain": {
64 | "node": "10.15.3",
65 | "yarn": "1.15.2"
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/src/AttributeValueParser.ts:
--------------------------------------------------------------------------------
1 | import { AttributeValue } from "@opticss/element-analysis";
2 | import * as nearley from "nearley";
3 | const grammar: nearley.CompiledRules = require("./grammar/attrvalue");
4 |
5 | export interface AttributeFlags {
6 | [attrName: string]: boolean;
7 | }
8 |
9 | const WHITESPACE_ATTRIBUTES: AttributeFlags = {
10 | "class": true,
11 | };
12 |
13 | // All attributes that are considered plaintext and cannot contain expressions.
14 | const TEXT_ATTRIBUTES: AttributeFlags = {
15 | "title": true, "media": true, "content": true, "style": true,
16 | };
17 |
18 | export class AttributeValueParser {
19 | whitespaceAttributes: AttributeFlags;
20 | textAttributes: AttributeFlags;
21 | plainHtml: boolean;
22 | constructor(plainHtml = false, textAttributes: AttributeFlags = {}, whitespaceAttributes: AttributeFlags = {}) {
23 | this.textAttributes = {...TEXT_ATTRIBUTES, ...textAttributes};
24 | this.whitespaceAttributes = {...WHITESPACE_ATTRIBUTES, ...whitespaceAttributes};
25 | // support for normal html instead of dynamic attribute expressions.
26 | this.plainHtml = plainHtml;
27 | }
28 | parse(attrNamespace: string | null | undefined, attrName: string, value: string): AttributeValue {
29 |
30 | // Attributes are whitespace delimited if they are `class` attributes with now namespace.
31 | let attrKey = attrName;
32 | if (attrNamespace) attrKey = `${attrNamespace}:${attrKey}`;
33 | let whitespaceDelimited = this.whitespaceAttributes[attrKey];
34 |
35 | // If whitespace delimited, be sure to trim unused whitespace.
36 | if (whitespaceDelimited) {
37 | value = value.trim();
38 | }
39 |
40 | // If begins with `javascript:`, or is an `onEvent` attr, it's script -- ignore
41 | if (attrName.match(/^on/) || value.startsWith("javascript:")) {
42 | return { absent: true };
43 | }
44 |
45 | // If it's a plain text attribute, or is a non-whitespace delimited attr in
46 | // an HTML document, return the constant value.
47 | if (this.textAttributes[attrKey] || (!whitespaceDelimited && this.plainHtml)) {
48 | return { constant: value };
49 | }
50 |
51 | // Parse the grammar, return AttributeValue object.
52 | let grammarObj = nearley.Grammar.fromCompiled(grammar);
53 | grammarObj.start = whitespaceDelimited ? "whitespaceDelimitedAttribute" : "attribute"; // because this api is stupid.
54 | let parser = new nearley.Parser(grammarObj);
55 | parser.feed(value);
56 | let res = parser.finish();
57 | return res[0];
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./AttributeValueParser";
2 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/test/mocha.opts:
--------------------------------------------------------------------------------
1 | --reporter spec
2 | --require source-map-support/register
3 | --inline-diffs
4 |
5 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/test/parser-test.ts:
--------------------------------------------------------------------------------
1 | import {
2 | assert,
3 | } from "chai";
4 | import {
5 | suite,
6 | test,
7 | } from "mocha-typescript";
8 |
9 | import { AttributeValueParser } from "../src";
10 |
11 | @suite("Simple Templates")
12 | export class SimpleTemplateTest {
13 | @test "Can parse"() {
14 | let parser = new AttributeValueParser();
15 | let value = parser.parse(null, "class", "(foo | bar)");
16 | assert.deepEqual(value, {oneOf: [{constant: "foo"}, {constant: "bar"}]});
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "dist",
5 | "baseUrl": "dist",
6 | "types": [
7 | "@types/chai",
8 | "@types/node",
9 | "@types/mocha"
10 | ]
11 | },
12 | "include": [
13 | "src",
14 | "test"
15 | ],
16 | "exclude": [
17 | "dist",
18 | "node_modules"
19 | ],
20 | "references": [
21 | {"path": "../code-style"},
22 | {"path": "../element-analysis"}
23 | ]
24 | }
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/tslint.cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/tslint",
3 | "extends": "@opticss/code-style/configs/tslint.cli.json"
4 | }
5 |
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@opticss/code-style/configs/tslint.interactive.json"
3 | }
--------------------------------------------------------------------------------
/packages/@opticss/attr-analysis-dsl/tslint.release.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/tslint",
3 | "extends": "@opticss/code-style/configs/tslint.release.json"
4 | }
5 |
--------------------------------------------------------------------------------
/packages/@opticss/code-style/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "node",
9 | "request": "launch",
10 | "name": "Launch via NPM",
11 | "cwd": "${workspaceFolder}",
12 | "runtimeExecutable": "npm",
13 | "runtimeArgs": [
14 | "run-script",
15 | "debug"
16 | ],
17 | "port": 9229
18 | }
19 | ]
20 | }
--------------------------------------------------------------------------------
/packages/@opticss/code-style/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cSpell.words": [
3 | "transpiled"
4 | ]
5 | }
--------------------------------------------------------------------------------
/packages/@opticss/code-style/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file.
4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5 |
6 | # [0.6.0](https://github.com/linkedin/opticss/compare/@opticss/code-style@0.5.0...@opticss/code-style@0.6.0) (2019-04-25)
7 |
8 |
9 | ### Features
10 |
11 | * Replace prefer-whatever-to-any with prefer-unknown-to-any. ([c1bbadc](https://github.com/linkedin/opticss/commit/c1bbadc))
12 |
13 |
14 | ### BREAKING CHANGES
15 |
16 | * The lint rule prefer-whatever-to-any is no longer valid
17 | because it relies on a type that was removed. The new
18 | prefer-unknown-to-any lint rule should be used instead. An error is
19 | raised if there's a configuration that enables the old rule.
20 |
21 |
22 |
23 |
24 |
25 | # 0.5.0 (2019-04-19)
26 |
27 |
28 |
29 | # 0.4.0 (2018-10-19)
30 |
31 |
32 | ### Features
33 |
34 | * Manually throw error for Node 6 in Optimizer. ([c4db789](https://github.com/linkedin/opticss/commit/c4db789))
35 |
36 |
37 |
38 | # 0.3.0 (2018-04-24)
39 |
40 |
41 |
42 | # 0.3.0-rc.0 (2018-04-24)
43 |
44 |
45 |
46 |
47 |
48 |
49 | # [0.3.0](https://github.com/linkedin/opticss/compare/v0.3.0-rc.0...v0.3.0) (2018-04-24)
50 |
51 | **Note:** Version bump only for package @opticss/code-style
52 |
--------------------------------------------------------------------------------
/packages/@opticss/code-style/configs/tslint.interactive.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/tslint",
3 | "rules": {
4 | "no-var-keyword": true,
5 | "adjacent-overload-signatures": true,
6 | "no-for-in-array":true,
7 | "prefer-unknown-to-any": true,
8 | "no-reference": true,
9 | "no-eval": true,
10 | "no-floating-promises": true,
11 | "no-invalid-template-strings": true,
12 | "no-string-throw": true,
13 | "switch-default": true,
14 | "no-unnecessary-type-assertion": true,
15 | "label-position": true,
16 | "no-construct": true,
17 | "no-duplicate-variable": true,
18 | "no-inferrable-types": true,
19 | "no-unused-expression": true,
20 | "semicolon": [true, "always"],
21 | "triple-equals": true,
22 | "class-name": true,
23 | "no-default-export": true,
24 | "new-parens": true,
25 | "variable-name": [
26 | true,
27 | "check-format",
28 | "ban-keywords",
29 | "allow-leading-underscore"
30 | ],
31 | "no-redundant-jsdoc": true,
32 | "binary-expression-operand-order": true,
33 | "prefer-for-of": true,
34 | "max-line-length": [
35 | false,
36 | {"limit": 120}
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/packages/@opticss/code-style/configs/tslint.release.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/tslint",
3 | "extends": "./tslint.cli.json",
4 | "rules": {
5 | "no-debugger": true,
6 | "no-console": [true, "log"]
7 | }
8 | }
--------------------------------------------------------------------------------
/packages/@opticss/code-style/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@opticss/code-style",
3 | "author": "Chris Eppstein",
4 | "description": "Configuration and tools to manage the code style of css-blocks.",
5 | "license": "BSD-2-Clause",
6 | "version": "0.6.0",
7 | "main": "configs/tslint.interactive.json",
8 | "readme": "README.md",
9 | "keywords": [
10 | "tslint",
11 | "tslint-plugin"
12 | ],
13 | "types": "dist",
14 | "scripts": {
15 | "compile": "which tsc && tsc --version && tsc --build",
16 | "pretest": "yarn run compile",
17 | "which": "echo $PATH",
18 | "test": "tslint --test test/rules/*/*",
19 | "debug": "echo `pwd` && node --inspect-brk=9229 tslint --test test/rules/*/*",
20 | "posttest": "yarn run lint",
21 | "lint": "tslint -t msbuild -p . -c tslint.cli.json",
22 | "lintall": "tslint -t msbuild -p . -c tslint.release.json",
23 | "lintfix": "tslint -t msbuild -p . --fix -c tslint.cli.json",
24 | "prepublishOnly": "yarn run compile && yarn run lintall"
25 | },
26 | "bugs": {
27 | "url": "https://github.com/linkedin/opticss/issues?q=is%3Aopen+is%3Aissue+label%3Apkg%3Acode-style"
28 | },
29 | "repository": {
30 | "url": "https://github.com/linkedin/opticss.git",
31 | "type": "git"
32 | },
33 | "homepage": "https://github.com/linkedin/opticss/tree/master/packages/%40opticss/code-style",
34 | "engines": {
35 | "node": "6.* || 8.* || >= 10.*"
36 | },
37 | "publishConfig": {
38 | "access": "public"
39 | },
40 | "peerDependencies": {
41 | "tslint": "^5.10.0",
42 | "typescript": "~3.4.4"
43 | },
44 | "files": [
45 | "dist",
46 | "configs",
47 | "*.md",
48 | "test"
49 | ],
50 | "gitHead": "ef310cb1b10dbc90cae4f859da146863f99d940b",
51 | "toolchain": {
52 | "node": "10.15.3",
53 | "yarn": "1.15.2"
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/packages/@opticss/code-style/src/index.ts:
--------------------------------------------------------------------------------
1 | // tslint:disable-next-line:no-default-export
2 | export default "hi";
3 |
--------------------------------------------------------------------------------
/packages/@opticss/code-style/src/rules/index.ts:
--------------------------------------------------------------------------------
1 | // tslint:disable-next-line:no-default-export
2 | export default {
3 | rulesDirectory: ".",
4 | };
5 |
--------------------------------------------------------------------------------
/packages/@opticss/code-style/src/rules/preferUnknownToAnyRule.ts:
--------------------------------------------------------------------------------
1 | import * as Lint from "tslint";
2 | import * as ts from "typescript";
3 |
4 | export class Rule extends Lint.Rules.AbstractRule {
5 | public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
6 | return this.applyWithWalker(new PreferUnknownToAny(sourceFile, this.getOptions()));
7 | }
8 | }
9 |
10 | // The walker takes care of all the work.
11 | class PreferUnknownToAny extends Lint.RuleWalker {
12 | visitAnyKeyword(node: ts.Node): void {
13 | let fix = this.createReplacement(node.getStart(), 3, "unknown");
14 | this.addFailureAtNode(node, "Using `any` is usually a bad idea. Consider using `unknown` instead.", fix);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/packages/@opticss/code-style/src/rules/preferWhateverToAnyRule.ts:
--------------------------------------------------------------------------------
1 | import * as Lint from "tslint";
2 | import * as ts from "typescript";
3 |
4 | export class Rule extends Lint.Rules.AbstractRule {
5 | public apply(_sourceFile: ts.SourceFile): Lint.RuleFailure[] {
6 | throw new Error("prefer-whatever-to-any has been replaced by prefer-unknown-to-any. Please update your configuration.");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/packages/@opticss/code-style/test/rules/multiline-parameters/args.ts.fix:
--------------------------------------------------------------------------------
1 | const foo = (
2 | asdf,
3 | xyz
4 | ) => {
5 | return true;
6 | };
7 |
8 | const foo = (
9 | asdf,
10 | ...baz
11 | ) => { return true; }
12 |
13 | const foo = (
14 | asdf,
15 | baz
16 | ) => { return true; }
17 |
18 | const foo = (
19 | asdf,
20 | ...baz
21 | ) => { return true; }
22 |
23 | const foo = function(
24 | asdf,
25 | xyz
26 | ) {
27 | return true;
28 | };
29 |
30 | function foo(
31 | asdf,
32 | xyz
33 | ) {
34 | }
35 |
36 | class Foo {
37 | constructor(
38 | one,
39 | two
40 | ) {
41 |
42 | }
43 | foo(asdf: boolean, xyz: string) {
44 | }
45 | fooBar(
46 | asdf: boolean,
47 | xyz: "asdf"
48 | );
49 | fooBar(
50 | asdf: boolean,
51 | xyz: string
52 | ) {
53 | }
54 | }
55 |
56 | const f = new Foo(
57 | 1,
58 | 2);
59 |
60 | (new Foo()).fooBar(
61 | true,
62 | "asdf");
63 |
64 | foo(
65 | "asdf",
66 | "xyz");
67 |
68 |
69 | @decorate(
70 | "first",
71 | "second)
72 | const foo = 1;
--------------------------------------------------------------------------------
/packages/@opticss/code-style/test/rules/multiline-parameters/args.ts.lint:
--------------------------------------------------------------------------------
1 | const foo = (asdf,
2 | ~~~~ [Newline expected before first multi-line parameter.]
3 | xyz) => {
4 | ~~~ [Newline expected after last multi-line parameter.]
5 | return true;
6 | };
7 |
8 | const foo = (
9 | asdf,
10 | ...baz) => { return true; }
11 | ~~~~~~ [Newline expected after last multi-line parameter.]
12 |
13 | const foo = (
14 | asdf,
15 | baz) => { return true; }
16 | ~~~[Newline expected after last multi-line parameter.]
17 |
18 | const foo = (
19 | asdf,
20 | ...baz
21 | ) => { return true; }
22 |
23 | const foo = function(asdf,
24 | ~~~~ [Newline expected before first multi-line parameter.]
25 | xyz) {
26 | ~~~ [Newline expected after last multi-line parameter.]
27 | return true;
28 | };
29 |
30 | function foo(asdf,
31 | ~~~~ [Newline expected before first multi-line parameter.]
32 | xyz) {
33 | ~~~ [Newline expected after last multi-line parameter.]
34 | }
35 |
36 | class Foo {
37 | constructor(one,
38 | ~~~ [Newline expected before first multi-line parameter.]
39 | two) {
40 | ~~~ [Newline expected after last multi-line parameter.]
41 |
42 | }
43 | foo(asdf: boolean, xyz: string) {
44 | }
45 | fooBar(asdf: boolean,
46 | ~~~~~~~~~~~~~ [Newline expected before first multi-line parameter.]
47 | xyz: "asdf");
48 | ~~~~~~~~~~~ [Newline expected after last multi-line parameter.]
49 | fooBar(asdf: boolean,
50 | ~~~~~~~~~~~~~ [Newline expected before first multi-line parameter.]
51 | xyz: string) {
52 | ~~~~~~~~~~~ [Newline expected after last multi-line parameter.]
53 | }
54 | }
55 |
56 | const f = new Foo(1,
57 | ~ [Newline expected before first multi-line argument.]
58 | 2);
59 |
60 | (new Foo()).fooBar(true,
61 | ~~~~ [Newline expected before first multi-line argument.]
62 | "asdf");
63 |
64 | foo("asdf",
65 | ~~~~~~ [Newline expected before first multi-line argument.]
66 | "xyz");
67 |
68 |
69 | @decorate("first",
70 | ~~~~~~~ [Newline expected before first multi-line argument.]
71 | "second)
72 | const foo = 1;
--------------------------------------------------------------------------------
/packages/@opticss/code-style/test/rules/multiline-parameters/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tslint-test.json"
3 | }
--------------------------------------------------------------------------------
/packages/@opticss/code-style/test/rules/prefer-unknown-to-any/test.ts.lint:
--------------------------------------------------------------------------------
1 | let foo: () => any;
2 | ~~~ [Using `any` is usually a bad idea. Consider using `unknown` instead.]
3 |
4 | function foo(bar: any): any {
5 | ~~~ [Using `any` is usually a bad idea. Consider using `unknown` instead.]
6 | ~~~ [Using `any` is usually a bad idea. Consider using `unknown` instead.]
7 | return true;
8 | }
--------------------------------------------------------------------------------
/packages/@opticss/code-style/test/rules/prefer-unknown-to-any/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tslint-test.json"
3 | }
--------------------------------------------------------------------------------
/packages/@opticss/code-style/test/rules/tslint-test.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": "../../dist/rules",
3 | "rules": {
4 | "multiline-parameters": true,
5 | "prefer-unknown-to-any": true
6 | }
7 | }
--------------------------------------------------------------------------------
/packages/@opticss/code-style/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../../tsconfig.json",
3 | "include": [
4 | "**/*.ts"
5 | ],
6 | "compilerOptions": {
7 | "rootDir": "src",
8 | "outDir": "dist",
9 | "baseUrl": "dist",
10 | "types": [
11 | "@types/chai",
12 | "@types/node",
13 | "@types/mocha"
14 | ]
15 | }
16 | }
--------------------------------------------------------------------------------
/packages/@opticss/code-style/tslint.cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/tslint",
3 | "extends": "./configs/tslint.cli.json"
4 | }
5 |
--------------------------------------------------------------------------------
/packages/@opticss/code-style/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./configs/tslint.release.json"
3 | }
--------------------------------------------------------------------------------
/packages/@opticss/code-style/tslint.release.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/tslint",
3 | "extends": "./configs/tslint.release.json"
4 | }
5 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["env"],
3 | "plugins": ["transform-es2015-modules-commonjs"],
4 | "only": "./dest/**/*.js",
5 | "sourceType": "module"
6 | }
7 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | demo/
3 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/.npmignore:
--------------------------------------------------------------------------------
1 | demo/
2 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file.
4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5 |
6 | ## [0.5.7](https://github.com/linkedin/opticss/compare/@opticss/demo-app@0.5.6...@opticss/demo-app@0.5.7) (2020-09-13)
7 |
8 | **Note:** Version bump only for package @opticss/demo-app
9 |
10 |
11 |
12 |
13 |
14 | ## [0.5.6](https://github.com/linkedin/opticss/compare/@opticss/demo-app@0.5.5...@opticss/demo-app@0.5.6) (2020-08-06)
15 |
16 | **Note:** Version bump only for package @opticss/demo-app
17 |
18 |
19 |
20 |
21 |
22 | ## [0.5.5](https://github.com/linkedin/opticss/compare/@opticss/demo-app@0.5.4...@opticss/demo-app@0.5.5) (2020-08-04)
23 |
24 | **Note:** Version bump only for package @opticss/demo-app
25 |
26 |
27 |
28 |
29 |
30 | ## [0.5.4](https://github.com/linkedin/opticss/compare/@opticss/demo-app@0.5.3...@opticss/demo-app@0.5.4) (2019-12-09)
31 |
32 | **Note:** Version bump only for package @opticss/demo-app
33 |
34 |
35 |
36 |
37 |
38 | ## [0.5.3](https://github.com/linkedin/opticss/compare/@opticss/demo-app@0.5.2...@opticss/demo-app@0.5.3) (2019-09-16)
39 |
40 | **Note:** Version bump only for package @opticss/demo-app
41 |
42 |
43 |
44 |
45 |
46 | ## [0.5.2](https://github.com/linkedin/opticss/compare/@opticss/demo-app@0.5.1...@opticss/demo-app@0.5.2) (2019-05-02)
47 |
48 | **Note:** Version bump only for package @opticss/demo-app
49 |
50 |
51 |
52 |
53 |
54 | ## [0.5.1](https://github.com/linkedin/opticss/compare/@opticss/demo-app@0.5.0...@opticss/demo-app@0.5.1) (2019-04-30)
55 |
56 |
57 | ### Bug Fixes
58 |
59 | * Upgrade parse5 to 5.0.0 to enable browser builds. ([6a88a33](https://github.com/linkedin/opticss/commit/6a88a33))
60 |
61 |
62 |
63 |
64 |
65 | # [0.5.0](https://github.com/linkedin/opticss/compare/@opticss/demo-app@0.4.1...@opticss/demo-app@0.5.0) (2019-04-25)
66 |
67 | **Note:** Version bump only for package @opticss/demo-app
68 |
69 |
70 |
71 |
72 |
73 | ## 0.4.1 (2019-04-19)
74 |
75 |
76 | ### Bug Fixes
77 |
78 | * **types:** Ignore errors for null document locations. ([2468cc7](https://github.com/linkedin/opticss/commit/2468cc7))
79 |
80 |
81 |
82 | # 0.4.0 (2018-10-19)
83 |
84 |
85 |
86 | # 0.3.0 (2018-04-24)
87 |
88 |
89 |
90 | # 0.3.0-rc.0 (2018-04-24)
91 |
92 |
93 |
94 |
95 |
96 |
97 | # [0.3.0](https://github.com/linkedin/opticss/compare/v0.3.0-rc.0...v0.3.0) (2018-04-24)
98 |
99 | **Note:** Version bump only for package @opticss/demo-app
100 |
101 |
102 |
103 |
104 |
105 |
106 | # [0.2.0](https://github.com/linkedin/opticss/compare/v0.1.1...v0.2.0) (2017-11-26)
107 |
108 |
109 |
110 |
111 | **Note:** Version bump only for package @opticss/demo-app
112 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/bin/opticss:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | const { DemoOptimizer } = require("@opticss/demo-cli");
4 |
5 | let optimizer = new DemoOptimizer("demo/input.html", "demo/input.css", "demo");
6 | optimizer.run();
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@opticss/demo-app",
3 | "private": "true",
4 | "version": "0.5.7",
5 | "description": "Demonstrates OptiCSS on simple html and css files.",
6 | "main": "dist/src/DemoOptimizer.js",
7 | "types": "dist/src/index.d.ts",
8 | "scripts": {
9 | "demo": "bin/opticss",
10 | "compile": "tsc --build && babel dist --out-dir dist && browserify --full-paths ./dist/src/index.js > ./dist/out.js",
11 | "pretest": "yarn run compile",
12 | "test": "mocha dist/test --opts test/mocha.opts",
13 | "posttest": "yarn run lint",
14 | "prepublishOnly": "yarn run compile && yarn run lintall",
15 | "lint": "tslint -t msbuild --project tsconfig.json -c tslint.cli.json",
16 | "lintall": "tslint -t msbuild --project tsconfig.json -c tslint.release.json",
17 | "lintfix": "tslint -t msbuild --project tsconfig.json -c tslint.cli.json --fix",
18 | "coverage": "istanbul cover -i \"dist/src/**/*.js\" --dir ./build/coverage _mocha -- dist/test --opts test/mocha.opts",
19 | "remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
20 | "docs": "typedoc --out ./docs .",
21 | "start": "node server.js",
22 | "watch": "watch 'yarn run compile' './src' './static' './test' --wait=1"
23 | },
24 | "bin": "bin/opticss",
25 | "repository": {
26 | "type": "git",
27 | "url": "git+https://github.com/linkedin/opticss.git"
28 | },
29 | "browser": {
30 | "css-size": "./dist/src/css-size-fake.js"
31 | },
32 | "author": "Chris Eppstein",
33 | "license": "BSD-2-Clause",
34 | "bugs": {
35 | "url": "https://github.com/linkedin/opticss/issues"
36 | },
37 | "homepage": "https://github.com/linkedin/opticss/tree/master/packages/%40opticss/demo-app",
38 | "dependencies": {
39 | "@opticss/simple-template": "^0.6.4",
40 | "@types/codemirror": "^0.0.74",
41 | "@types/prettier": "^1.7.0",
42 | "@types/split.js": "^1.3.0",
43 | "babel-cli": "^6.26.0",
44 | "codemirror": "^5.15.2",
45 | "express": "^4.15.5",
46 | "opticss": "^0.9.0",
47 | "parse5": "^5.0.0",
48 | "prettier": "1.17.1",
49 | "split.js": "^1.3.5"
50 | },
51 | "devDependencies": {
52 | "@opticss/code-style": "^0.6.0",
53 | "@opticss/util": "^0.7.0",
54 | "@types/mkdirp": "^0.5.1",
55 | "@types/parse5": "^5.0.0",
56 | "@types/rimraf": "^2.0.2",
57 | "babel-cli": "^6.26.0",
58 | "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
59 | "babel-preset-env": "^1.6.0",
60 | "browserify": "amiller-gh/browserify",
61 | "gzip-js": "^0.3.2",
62 | "mkdirp": "^0.5.1",
63 | "moo": "^0.5.0",
64 | "nearley": "^2.10.3",
65 | "rimraf": "^2.6.2",
66 | "source-map-support": "^0.5.3",
67 | "tslint": "^5.10.0",
68 | "typescript": "~3.4.4",
69 | "watch": "^1.0.2"
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/server.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const app = express();
3 |
4 | app.use('/src', express.static('src'));
5 | app.use('/dist', express.static('dist'));
6 | app.use('/node_modules', express.static('./node_modules'));
7 | app.use('/node_modules', express.static('../../../node_modules'));
8 | app.use(express.static('static'));
9 |
10 | app.listen(3000, function () {
11 | console.log('Opticss demo server listening on port 3000!')
12 | });
13 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/src/css-size-fake.ts:
--------------------------------------------------------------------------------
1 | const gzip = require("gzip-js");
2 |
3 | // TODO: Add in-app brotli compression.
4 |
5 | function getBinarySize(str: string) {
6 | return Buffer.byteLength(str, "utf8");
7 | }
8 |
9 | export interface SizeResults {
10 | in: number;
11 | out: number;
12 | inZip: number;
13 | outZip: number;
14 | // inBrotli: number;
15 | // outBrotli: number;
16 | }
17 |
18 | export function process(pre: string, opts: {level?: number}, post: () => Promise<{css: string}>): Promise {
19 | return post().then((post) => {
20 |
21 | let zipPre = gzip.zip(pre, {
22 | level: opts.level || 6,
23 | name: "pre.css",
24 | timestamp: Date.now() / 1000,
25 | });
26 |
27 | let zipPost = gzip.zip(post.css, {
28 | level: opts.level || 6,
29 | name: "post.css",
30 | timestamp: Date.now() / 1000,
31 | });
32 |
33 | return Promise.resolve({
34 | in: getBinarySize(pre),
35 | out: getBinarySize(post.css),
36 | inZip: zipPre.length,
37 | outZip: zipPost.length,
38 | });
39 | });
40 | }
41 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/src/simple-example.ts:
--------------------------------------------------------------------------------
1 | // This file is used in the OptiCSS README. If it requires changing, update the README too.
2 | import { unknownElement } from "@opticss/element-analysis";
3 | import { Template, TemplateAnalysis, TemplateIntegrationOptions } from "@opticss/template-api";
4 | import * as fs from "fs";
5 | import { OptiCSSOptions, Optimizer } from "opticss";
6 |
7 | // App level control of enabled features, enabling a feature that
8 | // the template integration doesn't support, has no effect.
9 | const options: Partial = {
10 | rewriteIdents: { id: false, class: true },
11 | };
12 |
13 | // This value usually comes from the template integration library.
14 | const templateOptions: Partial = {
15 | rewriteIdents: { id: false, class: true },
16 | analyzedTagnames: true,
17 | };
18 |
19 | // A new optimizer instance is required for every optimization.
20 | let opticss = new Optimizer(options, templateOptions);
21 |
22 | // Usually the css file(s) being optimized come from a previous build step.
23 | // So opticss supports input source maps to ensure that errors and debugging
24 | // information is correctly reported.
25 | let cssFile = "build/assets/myapp.css";
26 | opticss.addSource({
27 | filename: cssFile,
28 | content: fs.readFileSync(cssFile, "utf-8"),
29 | sourceMap: fs.readFileSync(`${cssFile}.map`, "utf-8"),
30 | });
31 |
32 | // This example doesn't use an analyzer. Instead, we create an analysis that
33 | // describes an "unknown template" about which nothing is known.
34 | let analysis = new TemplateAnalysis(new Template("unknown.html"));
35 | // Any element that is unknown tells the optimizer that it must assume
36 | // that any two styles might be co-located on that element. This
37 | // forces the optimizer to be extremely conservative with cascade changes.
38 | analysis.elements.push(unknownElement());
39 | opticss.addAnalysis(analysis);
40 |
41 | // Perform the optimization and output the results.
42 | let outputName = "build/assets/optimized.css";
43 | // tslint:disable-next-line:no-floating-promises
44 | opticss.optimize(outputName).then(result => {
45 | fs.writeFileSync(outputName, result.output.content.toString(), "utf-8");
46 | fs.writeFileSync(`${outputName}.log`, result.actions.logStrings().join("\n"), "utf-8");
47 | // Source map information with opticss is of dubious value because sourcemaps cannot
48 | // represent mutations that turn multiple source bytes into a single output byte.
49 | // So the source map will only surface (at most) one of the source bytes that caused
50 | // an output byte to exist. The log has more in-depth information about what mutations were
51 | // performed.
52 | if (result.output.sourceMap) {
53 | fs.writeFileSync(`${outputName}.map`, result.output.sourceMap, "utf-8");
54 | }
55 | // When integrating with template analysis we would pass the optimization
56 | // styleMapping result to the template rewriter.
57 | //let rewriteInfo = result.styleMapping;
58 | });
59 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
55 |
56 |
60 |
61 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/test/demo-test.ts:
--------------------------------------------------------------------------------
1 | import { assert } from "chai";
2 | import { skip, suite } from "mocha-typescript";
3 |
4 | @suite("Demo App")
5 | export class DemoAppTest {
6 | @skip "TODO: Write tests"() {
7 | assert.ok(1);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/test/mocha.opts:
--------------------------------------------------------------------------------
1 | --reporter spec
2 | --require source-map-support/register
3 | --inline-diffs
4 |
5 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../../tsconfig.json",
3 | "compilerOptions": {
4 | "target": "es2015",
5 | "module": "commonjs",
6 | "lib": [ "es2016", "dom" ],
7 | "moduleResolution": "node",
8 | "noImplicitAny": true,
9 | "removeComments": false,
10 | "outDir": "dist",
11 | "baseUrl": "dist",
12 | "types": [
13 | "@types/chai",
14 | "@types/node",
15 | "@types/mocha"
16 | ],
17 | "paths": {
18 | "codemirror/*": [ "../types-local/codemirror" ],
19 | "parse5": ["../types-local/parse5/index.d.ts"],
20 | "parse5-sax-parser": ["../types-local/parse5-sax-parser/index.d.ts"]
21 | }
22 | },
23 | "include": [
24 | "src",
25 | "test"
26 | ],
27 | "exclude": [
28 | "dist",
29 | "node_modules"
30 | ],
31 | "references": [
32 | {"path": "../simple-template"},
33 | {"path": "../../opticss"}
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/tslint.cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/tslint",
3 | "extends": "@opticss/code-style/configs/tslint.cli.json"
4 | }
5 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@opticss/code-style/configs/tslint.interactive.json"
3 | }
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/tslint.release.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/tslint",
3 | "extends": "@opticss/code-style/configs/tslint.release.json"
4 | }
5 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/types-local/codemirror/index.d.ts:
--------------------------------------------------------------------------------
1 | declare module "codemirror/mode/css/css" {
2 | const content: any;
3 | export default content;
4 | }
5 |
6 | declare module "codemirror/mode/htmlmixed/htmlmixed" {
7 | const content: any;
8 | export default content;
9 | }
10 |
11 | declare module "codemirror/addon/hint/css-hint" {
12 | const content: any;
13 | export default content;
14 | }
15 |
16 | declare module "codemirror/addon/hint/show-hint" {
17 | const content: any;
18 | export default content;
19 | }
20 |
--------------------------------------------------------------------------------
/packages/@opticss/demo-app/types-local/codemirror/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {},
3 | "description": "TypeScript definitions for sigma",
4 | "name": "@types/codemirror",
5 | "typings": "index.d.ts",
6 | "version": "0.4.0"
7 | }
8 |
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/.vscode/cSpell.json:
--------------------------------------------------------------------------------
1 | // cSpell Settings
2 | {
3 | // Version of the setting file. Always 0.1
4 | "version": "0.1",
5 | // language - current active spelling language
6 | "language": "en",
7 | // words - list of words to be always considered correct
8 | "words": [
9 | "Combinator",
10 | "Combinators",
11 | "Eppstein",
12 | "Opti",
13 | "Opticss",
14 | "Rewritable",
15 | "Rewriteable",
16 | "Selectable",
17 | "Selectorish",
18 | "asdf",
19 | "atrule",
20 | "brotli",
21 | "classname",
22 | "contenteditable",
23 | "deserialize",
24 | "deserializer",
25 | "eppsteins",
26 | "idents",
27 | "klass",
28 | "mergeable",
29 | "mergeables",
30 | "nearley",
31 | "optimizable",
32 | "optimizer's",
33 | "promisify",
34 | "pseudoelement",
35 | "pseudoelements",
36 | "selectables",
37 | "serializable",
38 | "shorthands",
39 | "sourcemap",
40 | "superset",
41 | "supersets"
42 | ],
43 | // flagWords - list of words to be always considered incorrect
44 | // This is useful for offensive words and common spelling errors.
45 | // For example "hte" should be "the"
46 | "flagWords": [
47 | "hte"
48 | ]
49 | }
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible Node.js debug attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "node",
9 | "request": "launch",
10 | "name": "Launch Program",
11 | "preLaunchTask": "compile",
12 | "program": "${workspaceRoot}/node_modules/.bin/_mocha",
13 | "args": [
14 | "dist/test",
15 | "--opts",
16 | "test/mocha.opts"
17 | ],
18 | "cwd": "${workspaceRoot}",
19 | "outFiles": [
20 | "${workspaceRoot}/dist/**/*.js"
21 | ],
22 | "sourceMaps": true
23 | }
24 | ]
25 | }
26 |
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | // Place your settings in this file to overwrite default and user settings.
2 | {
3 | "files.exclude": {
4 | "**/dist/**/*": true,
5 | "**/*.lock": true
6 | },
7 | "editor.tabSize": 2,
8 | "typescriptHero.codeOutline.enabled": true,
9 | "typescriptHero.resolver.multiLineWrapThreshold": 10,
10 | "typescriptHero.resolver.multiLineTrailingComma": true,
11 | "typescriptHero.resolver.organizeOnSave": true,
12 | "typescript.tsdk": "node_modules/typescript/lib",
13 | "tslint.enable": true,
14 | "tslint.configFile": "tslint.json",
15 | "typescript.useCodeSnippetsOnMethodSuggest": true,
16 | "typescriptHero.resolver.ignorePatterns": [
17 | "dist",
18 | "node_modules",
19 | "test",
20 | "index.ts"
21 | ],
22 | "tslint.packageManager": "yarn",
23 | "npm.packageManager": "yarn"
24 | }
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "label": "compile",
8 | "type": "npm",
9 | "script": "compile",
10 | "problemMatcher": []
11 | }
12 | ]
13 | }
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file.
4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5 |
6 | ## [0.6.2](https://github.com/linkedin/opticss/compare/@opticss/element-analysis@0.6.1...@opticss/element-analysis@0.6.2) (2019-09-16)
7 |
8 | **Note:** Version bump only for package @opticss/element-analysis
9 |
10 |
11 |
12 |
13 |
14 | ## [0.6.1](https://github.com/linkedin/opticss/compare/@opticss/element-analysis@0.6.0...@opticss/element-analysis@0.6.1) (2019-04-30)
15 |
16 | **Note:** Version bump only for package @opticss/element-analysis
17 |
18 |
19 |
20 |
21 |
22 | # [0.6.0](https://github.com/linkedin/opticss/compare/@opticss/element-analysis@0.5.0...@opticss/element-analysis@0.6.0) (2019-04-25)
23 |
24 | **Note:** Version bump only for package @opticss/element-analysis
25 |
26 |
27 |
28 |
29 |
30 | # 0.5.0 (2019-04-19)
31 |
32 |
33 |
34 | # 0.4.0 (2018-10-19)
35 |
36 |
37 | ### Features
38 |
39 | * Manually throw error for Node 6 in Optimizer. ([c4db789](https://github.com/linkedin/opticss/commit/c4db789))
40 |
41 |
42 |
43 | # 0.3.0 (2018-04-24)
44 |
45 |
46 |
47 | # 0.3.0-rc.0 (2018-04-24)
48 |
49 |
50 |
51 |
52 |
53 |
54 | # [0.3.0](https://github.com/linkedin/opticss/compare/v0.3.0-rc.0...v0.3.0) (2018-04-24)
55 |
56 | **Note:** Version bump only for package @opticss/element-analysis
57 |
58 |
59 |
60 |
61 |
62 |
63 | # [0.2.0](https://github.com/linkedin/opticss/compare/v0.1.1...v0.2.0) (2017-11-26)
64 |
65 |
66 |
67 |
68 | **Note:** Version bump only for package @opticss/element-analysis
69 |
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@opticss/element-analysis",
3 | "version": "0.6.2",
4 | "description": "Data structures for storing the analysis of elements.",
5 | "main": "dist/src/index.js",
6 | "types": "dist/src/index.d.ts",
7 | "scripts": {
8 | "compile": "tsc --build",
9 | "pretest": "yarn run compile",
10 | "test": "mocha dist/test --opts test/mocha.opts",
11 | "posttest": "yarn run lint",
12 | "prepublishOnly": "yarn run compile && yarn run lintall",
13 | "lint": "tslint -t msbuild --project tsconfig.json -c tslint.cli.json",
14 | "lintall": "tslint -t msbuild --project tsconfig.json -c tslint.release.json",
15 | "lintfix": "tslint -t msbuild --project tsconfig.json -c tslint.cli.json --fix",
16 | "coverage": "istanbul cover -i \"dist/src/**/*.js\" --dir ./build/coverage _mocha -- dist/test --opts test/mocha.opts",
17 | "remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
18 | "docs": "typedoc --out ./docs ."
19 | },
20 | "repository": {
21 | "type": "git",
22 | "url": "git+https://github.com/linkedin/opticss.git"
23 | },
24 | "keywords": [
25 | "css",
26 | "cascade"
27 | ],
28 | "author": "Chris Eppstein",
29 | "license": "BSD-2-Clause",
30 | "bugs": {
31 | "url": "https://github.com/linkedin/opticss/issues?q=is%3Aopen+is%3Aissue+label%3Apkg%3Aelement-analysis"
32 | },
33 | "homepage": "https://github.com/linkedin/opticss/tree/master/packages/%40opticss/element-analysis",
34 | "engines": {
35 | "node": "6.* || 8.* || >= 10.*"
36 | },
37 | "publishConfig": {
38 | "access": "public"
39 | },
40 | "dependencies": {
41 | "@opticss/util": "^0.7.0"
42 | },
43 | "devDependencies": {
44 | "@opticss/code-style": "^0.6.0",
45 | "@types/chai": "^4.0.4",
46 | "@types/mocha": "^5.2.6",
47 | "chai": "^4.1.2",
48 | "istanbul": "^0.4.5",
49 | "mocha": "^6.1.4",
50 | "mocha-typescript": "^1.1.9",
51 | "remap-istanbul": "^0.13.0",
52 | "source-map-support": "^0.5.3",
53 | "tslint": "^5.10.0",
54 | "typedoc": "^0.15.0-0",
55 | "typescript": "~3.4.4"
56 | },
57 | "gitHead": "ef310cb1b10dbc90cae4f859da146863f99d940b",
58 | "toolchain": {
59 | "node": "10.15.3",
60 | "yarn": "1.15.2"
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/src/Element.ts:
--------------------------------------------------------------------------------
1 | import { Attr, Attribute, SerializedAttribute } from "./Attribute";
2 | import { attrValues } from "./attrValues";
3 | import { SourceLocation } from "./SourceLocation";
4 | import { POSITION_UNKNOWN, SourcePosition } from "./SourceLocation";
5 | import { SerializedTagname, Tag, Tagname } from "./Tagname";
6 |
7 | export type Selectable = Element | Tag | Attr;
8 |
9 | export interface ElementInfo {
10 | sourceLocation?: SourceLocation;
11 | tagname: TagnameType;
12 | attributes: Array;
13 | id?: string;
14 | }
15 |
16 | export type SerializedElementInfo = ElementInfo;
17 |
18 | export class Element implements ElementInfo {
19 | sourceLocation: SourceLocation;
20 | tagname: Tag;
21 | attributes: Array;
22 | id: string | undefined;
23 | constructor(tagname: Tag, attributes: Array, sourceLocation?: SourceLocation, id?: string) {
24 | this.tagname = tagname;
25 | this.attributes = attributes;
26 | this.sourceLocation = sourceLocation || {start: POSITION_UNKNOWN};
27 | this.id = id;
28 | }
29 |
30 | static fromElementInfo(info: ElementInfo): Element {
31 | return new Element(info.tagname, info.attributes, info.sourceLocation, info.id);
32 | }
33 |
34 | serialize(): SerializedElementInfo {
35 | let e: SerializedElementInfo = {
36 | tagname: this.tagname.toJSON(),
37 | attributes: this.attributes.map(a => a.toJSON()),
38 | };
39 | if (this.sourceLocation && this.sourceLocation.start.line >= 0) {
40 | e.sourceLocation = this.sourceLocation;
41 | }
42 | return e;
43 | }
44 | toString() {
45 | let parts = [];
46 | parts.push(this.tagname);
47 | for (let attr of this.attributes) {
48 | parts.push(attr);
49 | }
50 | return `<${parts.join(" ")}>`;
51 | }
52 | }
53 |
54 | /**
55 | * Returns an unknown element. Use of this element in an analysis
56 | * has the effect of putting the optimizer into a conservative optimization
57 | * mode since there's no longer any guarantees about what values maybe be
58 | * correlated on the element's attributes. Essentially, every selector will
59 | * match this element.
60 | *
61 | * @param [unknownAttrs=["class", "id"]] Which attributes should be marked as unknown.
62 | * @param [startPosition] if the start position is known it can be provided.
63 | * @param [endPosition] if the end position is known it can be provided.
64 | */
65 | export function unknownElement(unknownAttrs = ["class", "id"], startPosition?: SourcePosition, endPosition?: SourcePosition): Element {
66 | let tagname = new Tagname(attrValues.unknown());
67 | let attrs = new Array();
68 | for (let attrName of unknownAttrs) {
69 | attrs.push(new Attribute(attrName, attrValues.unknown()));
70 | }
71 | let loc: SourceLocation | undefined = undefined;
72 | if (startPosition) {
73 | loc = {start: startPosition};
74 | if (endPosition) {
75 | loc.end = endPosition;
76 | }
77 | }
78 | return new Element(tagname, attrs, loc);
79 | }
80 |
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/src/SourceLocation.ts:
--------------------------------------------------------------------------------
1 | export const POSITION_UNKNOWN: SourcePosition = { line: -1 };
2 |
3 | export interface SourcePosition {
4 | filename?: string;
5 | line: number;
6 | column?: number;
7 | }
8 |
9 | export function isSourcePosition(position: object): position is SourcePosition {
10 | return !!((position).line);
11 | }
12 |
13 | export interface SourceLocation {
14 | start: SourcePosition;
15 | end?: SourcePosition;
16 | }
17 |
18 | export function isSourceLocation(location: object): location is SourceLocation {
19 | return !!((location).start);
20 | }
21 |
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/src/attrValues.ts:
--------------------------------------------------------------------------------
1 | import {
2 | AttributeValueChoice,
3 | AttributeValueChoiceOption,
4 | AttributeValueSet,
5 | AttributeValueSetItem,
6 | ValueAbsent,
7 | ValueConstant,
8 | ValueEndsWith,
9 | ValueStartsAndEndsWith,
10 | ValueStartsWith,
11 | ValueUnknown,
12 | ValueUnknownIdentifier,
13 | } from "./Attribute";
14 |
15 | export namespace attrValues {
16 | export function constant(constant: string): ValueConstant {
17 | return {constant};
18 | }
19 | export function unknown(): ValueUnknown {
20 | return {unknown: true};
21 | }
22 | export function unknownIdentifier(): ValueUnknownIdentifier {
23 | return {unknownIdentifier: true};
24 | }
25 | export function absent(): ValueAbsent {
26 | return {absent: true};
27 | }
28 | export function startsWith(startsWith: string, whitespace?: boolean): ValueStartsWith {
29 | return {startsWith, whitespace};
30 | }
31 | export function endsWith(endsWith: string, whitespace?: boolean): ValueEndsWith {
32 | return {endsWith, whitespace};
33 | }
34 | export function startsAndEndsWith(startsWith: string, endsWith: string, whitespace?: boolean): ValueStartsAndEndsWith {
35 | return {startsWith, endsWith, whitespace};
36 | }
37 | export function allOf(allOf: Array): AttributeValueSet {
38 | return {allOf};
39 | }
40 | export function oneOf(oneOf: Array): AttributeValueChoice {
41 | return {oneOf};
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./Attribute";
2 | export * from "./attrValues";
3 | export * from "./Element";
4 | export * from "./SourceLocation";
5 | export * from "./Tagname";
6 |
--------------------------------------------------------------------------------
/packages/@opticss/element-analysis/test/element-analysis-test.ts:
--------------------------------------------------------------------------------
1 | import { assert } from "chai";
2 | import { suite, test } from "mocha-typescript";
3 |
4 | import {
5 | Attribute,
6 | AttributeValueSet,
7 | Element,
8 | Tagname,
9 | attrValues,
10 | } from "../src";
11 |
12 | @suite("Element Analysis")
13 | export class ElementAnalysisTest {
14 | @test "attribute value generators"() {
15 | assert.deepEqual(attrValues.absent(), {absent: true});
16 | assert.deepEqual(attrValues.allOf([attrValues.constant("foo")]), {
17 | allOf: [{constant: "foo"}],
18 | });
19 | }
20 | @test "css-blocks class analysis"() {
21 | let value: AttributeValueSet = JSON.parse('{"allOf":[{"constant":"header__emphasis"},{"constant":"typography__underline"},{"oneOf":[{"allOf":[{"constant":"with-dynamic-classes__world"},{"oneOf":[{"absent":true},{"constant":"with-dynamic-classes__world--thick"}]}]},{"absent":true}]},{"oneOf":[{"absent":true},{"constant":"header__emphasis--style-bold"},{"constant":"header__emphasis--style-italic"}]}]}');
22 | let element = new Element(new Tagname(attrValues.constant("span")), [new Attribute("class", value)]);
23 | assert.deepEqual(element.toString(), '