Skip to content
Permalink
Browse files

Merge pull request #355 from linkedin/find-class-references

Phase 1 of "find references"
  • Loading branch information
jackson-dean committed Nov 27, 2019
2 parents 2a0fe1b + ddaed86 commit 15c4f266d9709292fcc9c96d2af621009767036a
Showing with 4,774 additions and 1,772 deletions.
  1. +39 −14 packages/@css-blocks/broccoli/test/Analyze.ts
  2. +5 −2 packages/@css-blocks/broccoli/test/Transport.ts
  3. +5 −10 packages/@css-blocks/core/src/Analyzer/Analyzer.ts
  4. +2 −1 packages/@css-blocks/core/test/opticss-test.ts
  5. +28 −27 packages/@css-blocks/core/test/template-analysis-test.ts
  6. +4 −4 packages/@css-blocks/core/test/validations/attribute-group-validator-test.ts
  7. +4 −4 packages/@css-blocks/core/test/validations/attribute-parent-validator-test.ts
  8. +2 −3 packages/@css-blocks/core/test/validations/class-pairs-validator-test.ts
  9. +1 −1 packages/@css-blocks/core/test/validations/property-conflict-validator-test.ts
  10. +3 −3 packages/@css-blocks/core/test/validations/root-class-validator-test.ts
  11. +4 −4 packages/@css-blocks/core/test/validations/validator-test.ts
  12. +2 −2 packages/@css-blocks/ember-cli/index.js
  13. +4 −6 packages/@css-blocks/glimmer/src/Analyzer.ts
  14. +27 −27 packages/@css-blocks/glimmer/test/stylesheet-analysis-test.ts
  15. +6 −6 packages/@css-blocks/glimmer/test/template-rewrite-test.ts
  16. +5 −2 packages/@css-blocks/jsx/src/Analyzer/index.ts
  17. +1 −1 packages/@css-blocks/language-server/package.json
  18. +17 −1 packages/@css-blocks/language-server/src/Server.ts
  19. +1 −0 packages/@css-blocks/language-server/src/serverCapabilities.ts
  20. +1 −1 packages/@css-blocks/language-server/src/util/createFocusPath.ts
  21. +2 −1 packages/@css-blocks/webpack/test/configs/basicConfig.ts
  22. +1 −1 packages/@css-blocks/webpack/test/configs/templateConfig.ts
  23. +4,610 −1,651 yarn.lock
@@ -1,3 +1,4 @@
import { BlockFactory } from "@css-blocks/core";
import { GlimmerAnalyzer } from "@css-blocks/glimmer";
import * as assert from "assert";
import { TempDir, createBuilder, createTempDir } from "broccoli-test-helper";
@@ -37,14 +38,14 @@ describe("Broccoli Analyze Plugin Test", function () {
});

let transport = new Transport("test-transport");
let analyzer = new GlimmerAnalyzer({}, {}, {
let analyzer = new GlimmerAnalyzer(new BlockFactory({}), {}, {
app: { name: "test" },
types: {
stylesheet: { definitiveCollection: "components" },
template: { definitiveCollection: "components" },
},
collections: {
components: { group: "ui", types: [ "template", "stylesheet" ] },
components: { group: "ui", types: ["template", "stylesheet"] },
},
});
let output = createBuilder(new CSSBlocksAnalyze(
@@ -82,9 +83,15 @@ describe("Broccoli Analyze Plugin Test", function () {
// Accidental modification of output directory does not make the plugin explode.
fs.unlinkSync(output.path("src/ui/components/Chrisrng/template.hbs"));
input.write({
src: { ui: { components: { [entryComponentName]: {
"stylesheet.css": `:scope { color: blue; } .foo { color: yellow; }`,
}}}},
src: {
ui: {
components: {
[entryComponentName]: {
"stylesheet.css": `:scope { color: blue; } .foo { color: yellow; }`,
},
},
},
},
});
await output.build();
assert.equal(preDiff.calculatePatch(postDiff).length, 0, "Input directory unchanged after rebuild.");
@@ -93,29 +100,47 @@ describe("Broccoli Analyze Plugin Test", function () {

// Removal of block files trigger build but result in no tree changes.
input.write({
src: { ui: { components: { [entryComponentName]: {
"stylesheet.css": null,
}}}},
src: {
ui: {
components: {
[entryComponentName]: {
"stylesheet.css": null,
},
},
},
},
});
await output.build();
assert.equal(transport["css"], "", "Removal of block files trigger build but result in no output tree changes.");
assert.deepEqual(output.changes(), {}, "Removal of block files trigger build but result in output no tree changes.");

// Addition of block files trigger build but result in no output tree changes.
input.write({
src: { ui: { components: { [entryComponentName]: {
"stylesheet.css": `:scope { color: red; } .foo { color: green; }`,
}}}},
src: {
ui: {
components: {
[entryComponentName]: {
"stylesheet.css": `:scope { color: red; } .foo { color: green; }`,
},
},
},
},
});
await output.build();
assert.equal(transport["css"], ".a { color: red; } .b { color: green; }", "Addition of block files trigger build but result in no output tree changes.");
assert.deepEqual(output.changes(), {}, "Addition of block files trigger build but result in no output tree changes.");

// Modifications to non-block files are funneled through to output.
input.write({
src: { ui: { components: { [entryComponentName]: {
"template.hbs": `<div><h1>Welcome to Glimmer!</h1></div>`,
}}}},
src: {
ui: {
components: {
[entryComponentName]: {
"template.hbs": `<div><h1>Welcome to Glimmer!</h1></div>`,
},
},
},
},
});
await output.build();
assert.equal(transport["css"], ".a { color: red; }");
@@ -1,4 +1,4 @@
import { Block, StyleMapping } from "@css-blocks/core";
import { Block, BlockFactory, StyleMapping } from "@css-blocks/core";
import { GlimmerAnalyzer } from "@css-blocks/glimmer";
import * as assert from "assert";

@@ -14,7 +14,10 @@ describe("Broccoli Transport Test", () => {
assert.equal(transport.mapping, undefined);

transport.css = "foobar";
transport.analyzer = new GlimmerAnalyzer({}, {}, { types: {}, collections: {} });
transport.analyzer = new GlimmerAnalyzer(new BlockFactory({}), {}, {
types: {},
collections: {},
});
transport.blocks.add(new Block("foo", "bar"));
transport.mapping = {} as StyleMapping<"GlimmerTemplates.ResolvedFile">;

@@ -8,11 +8,7 @@ import * as debugGenerator from "debug";

import { BlockFactory } from "../BlockParser";
import { Block, Style } from "../BlockTree";
import {
Options,
ResolvedConfiguration,
resolveConfiguration,
} from "../configuration";
import { ResolvedConfiguration } from "../configuration";

import { Analysis, SerializedAnalysis } from "./Analysis";
import { TemplateValidatorOptions } from "./validations";
@@ -39,22 +35,21 @@ export abstract class Analyzer<K extends keyof TemplateTypes> {
protected dynamicStyles: MultiMap<Style, Analysis<K>>;

constructor (
options?: Options,
blockFactory: BlockFactory,
analysisOpts?: AnalysisOptions,
) {

// TODO: Remove April 2019 when Node.js 6 is EOL'd
if (parseInt(process.versions.node) <= 6) {
throw new Error("CSS Blocks does not support Node.js <= 6");
}

this.cssBlocksOptions = resolveConfiguration(options);
this.blockFactory = blockFactory;
this.cssBlocksOptions = blockFactory.configuration;
this.validatorOptions = analysisOpts && analysisOpts.validations || {};
this.blockFactory = new BlockFactory(this.cssBlocksOptions);
this.analysisMap = new Map();
this.staticStyles = new MultiMap();
this.dynamicStyles = new MultiMap();
}
}

abstract analyze(dir: string, entryPoints: string[]): Promise<Analyzer<K>>;
abstract get optimizationOptions(): TemplateIntegrationOptions;
@@ -16,6 +16,7 @@ import { postcss } from "opticss";
import { Analysis, Analyzer } from "../src/Analyzer";
import { ElementAnalysis } from "../src/Analyzer";
import { BlockCompiler } from "../src/BlockCompiler";
import { BlockFactory } from "../src/BlockParser";
import { AttrValue, Block, BlockClass } from "../src/BlockTree";
import { resolveConfiguration } from "../src/configuration";
import { StyleMapping } from "../src/TemplateRewriter/StyleMapping";
@@ -93,7 +94,7 @@ export class TemplateAnalysisTests {
};
}
}
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory(config));
return analyzer.analyze().then(async (analyzer: TestAnalyzer) => {
let compiler = new BlockCompiler(postcss, config);
let optimizer = new Optimizer({}, { rewriteIdents: { id: false, class: true} });
@@ -32,7 +32,7 @@ export class AnalysisTests {
@test "can add styles from a block"() {
let config = resolveConfiguration({});
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory(config));
let analysis = analyzer.newAnalysis(info);
let css = `
:scope { color: blue; }
@@ -64,7 +64,7 @@ export class AnalysisTests {
@test "can add dynamic styles from a block"() {
let config = resolveConfiguration({});
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory(config));
let analysis = analyzer.newAnalysis(info);
let css = `
:scope { color: blue; }
@@ -98,7 +98,7 @@ export class AnalysisTests {
@test "can correlate styles"() {
let config = resolveConfiguration({});
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory(config));
let analysis = analyzer.newAnalysis(info);
let css = `
:scope { color: blue; }
@@ -139,7 +139,7 @@ export class AnalysisTests {
@test "can add styles from two blocks"() {
let config = resolveConfiguration({});
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory(config));
let analysis = analyzer.newAnalysis(info);
let css = `
:scope { color: blue; }
@@ -183,7 +183,7 @@ export class AnalysisTests {

@test "adding dynamic styles enumerates correlation in analysis"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { imports, config } = setupImporting();

@@ -234,7 +234,7 @@ export class AnalysisTests {

@test "multiple dynamic values added using `addExclusiveStyles` enumerate correlations correctly in analysis"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { config } = setupImporting();

@@ -273,7 +273,7 @@ export class AnalysisTests {

@test "multiple exclusive dynamic values added using enumerate correlations correctly in analysis"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { config } = setupImporting();

@@ -338,7 +338,7 @@ export class AnalysisTests {

@test "toggling between two classes with states of the same name"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { imports, config } = setupImporting();

@@ -392,7 +392,7 @@ export class AnalysisTests {

@test "addExclusiveStyles generates correct correlations when `alwaysPresent` is true"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { imports, config } = setupImporting();
imports.registerSource(
@@ -442,7 +442,7 @@ export class AnalysisTests {

@test "addExclusiveStyles generates correct correlations when `alwaysPresent` is false"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { imports, config } = setupImporting();
imports.registerSource(
@@ -488,7 +488,7 @@ export class AnalysisTests {
}
@test "can generate an analysis for the optimizer"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { imports, config } = setupImporting();
imports.registerSource(
@@ -563,9 +563,9 @@ export class AnalysisTests {

@test "correlating two classes from the same block on the same element throws an error"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analysis = analyzer.newAnalysis(info);
let config = resolveConfiguration({});
let analyzer = new TestAnalyzer(new BlockFactory(config));
let analysis = analyzer.newAnalysis(info);

let css = `
:scope { color: blue; }
@@ -590,9 +590,10 @@ export class AnalysisTests {

@test "built-in template validators may be configured with boolean values"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer({}, { validations: { "no-class-pairs": false }});
let analysis = analyzer.newAnalysis(info);
let config = resolveConfiguration({});
let blockFactory = new BlockFactory(config);
let analyzer = new TestAnalyzer(blockFactory, { validations: { "no-class-pairs": false }});
let analysis = analyzer.newAnalysis(info);

let css = `
:scope { color: blue; }
@@ -613,9 +614,9 @@ export class AnalysisTests {

@test "custom template validators may be passed to analysis"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer({}, { validations: { customValidator(data, _a, err) { if (data) err("CUSTOM ERROR"); } } });
let analysis = analyzer.newAnalysis(info);
let config = resolveConfiguration({});
let analyzer = new TestAnalyzer(new BlockFactory(config), { validations: { customValidator(data, _a, err) { if (data) err("CUSTOM ERROR"); } } });
let analysis = analyzer.newAnalysis(info);

let css = `
:scope { color: blue; }
@@ -633,9 +634,9 @@ export class AnalysisTests {

@test "adding both root and a class from the same block to the same elment throws an error"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analysis = analyzer.newAnalysis(info);
let config = resolveConfiguration({});
let analyzer = new TestAnalyzer(new BlockFactory(config));
let analysis = analyzer.newAnalysis(info);

let css = `
:scope { color: blue; }
@@ -661,9 +662,9 @@ export class AnalysisTests {

@test "adding both root and a state from the same block to the same element is allowed"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analysis = analyzer.newAnalysis(info);
let config = resolveConfiguration({});
let analyzer = new TestAnalyzer(new BlockFactory(config));
let analysis = analyzer.newAnalysis(info);

let css = `
:scope { color: blue; }
@@ -685,7 +686,7 @@ export class AnalysisTests {

@test "classes from other blocks may be added to the root element"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { imports, config } = setupImporting();

@@ -733,7 +734,7 @@ export class AnalysisTests {

@test "throws when states are applied without their parent root"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { config } = setupImporting();

@@ -755,7 +756,7 @@ export class AnalysisTests {

@test "throws when states are applied without their parent BlockClass"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { config } = setupImporting();

@@ -780,7 +781,7 @@ export class AnalysisTests {

@test "Throws when inherited states are applied without their root"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { imports, config } = setupImporting();

@@ -822,7 +823,7 @@ export class AnalysisTests {

@test "Inherited states pass validation when applied with their root"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { imports, config } = setupImporting();

@@ -863,7 +864,7 @@ export class AnalysisTests {

@test "composition test"() {
let info = new Template("templates/my-template.hbs");
let analyzer = new TestAnalyzer();
let analyzer = new TestAnalyzer(new BlockFactory({}));
let analysis = analyzer.newAnalysis(info);
let { imports, config } = setupImporting();

0 comments on commit 15c4f26

Please sign in to comment.
You can’t perform that action at this time.